package Algorithms.MaxSubarraySum

class DivideAndConquer {

    companion object {

        fun findMaxSubarraySum(array: IntArray): Int {
            return findMaxSubarrayDiapason(array, 0, array.size - 1).third
        }

        private fun findMaxSubarrayDiapason(
            array: IntArray,
            low: Int,
            high: Int
        ): Triple<Int, Int, Int> { //left,right,sun
            if (low == high)
                return Triple(low, high, array[low])

            val mid = (low + high) / 2
            val leftValues = findMaxSubarrayDiapason(array, low, mid)
            val rightValues = findMaxSubarrayDiapason(array, mid + 1, high)
            val middleValues = findMaxSubarrayCrosslines(array, low, mid, high)

            return if (leftValues.third >= rightValues.third && leftValues.third >= middleValues.third)
                leftValues
            else if (rightValues.third >= leftValues.third && rightValues.third >= middleValues.third)
                rightValues
            else middleValues

        }

        private fun findMaxSubarrayCrosslines(
            array: IntArray,
            low: Int,
            mid: Int,
            high: Int
        ): Triple<Int, Int, Int> { //left,right,sun

            var leftSum = Int.MIN_VALUE
            var rightSum = Int.MIN_VALUE
            var leftIdx = mid
            var rightIdx = mid + 1

            if (low == high)
                return Triple(low, high, array[low])

            var sum = 0
            for (i in mid downTo low) {
                sum += array[i]
                if (sum > leftSum) {
                    leftIdx = i
                    leftSum = sum
                }
            }

            sum = 0
            for (i in mid + 1..high) {
                sum += array[i]
                if (sum > rightSum) {
                    rightIdx = i
                    rightSum = sum
                }
            }

            return Triple(leftIdx, rightIdx, leftSum + rightSum)
        }

    }
}

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

  public final int findMaxSubarraySum(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String array
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: aload_1
      10: arraylength
      11: iconst_1
      12: isub
      13: invokespecial #25                 // Method findMaxSubarrayDiapason:([III)Lkotlin/Triple;
      16: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
      19: checkcast     #33                 // class java/lang/Number
      22: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      25: ireturn

  private final kotlin.Triple<java.lang.Integer, java.lang.Integer, java.lang.Integer> findMaxSubarrayDiapason(int[], int, int);
    Code:
       0: iload_2
       1: iload_3
       2: if_icmpne     27
       5: new           #27                 // class kotlin/Triple
       8: dup
       9: iload_2
      10: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: iload_3
      14: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: aload_1
      18: iload_2
      19: iaload
      20: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokespecial #48                 // Method kotlin/Triple."<init>":(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
      26: areturn
      27: iload_2
      28: iload_3
      29: iadd
      30: iconst_2
      31: idiv
      32: istore        4
      34: aload_0
      35: aload_1
      36: iload_2
      37: iload         4
      39: invokespecial #25                 // Method findMaxSubarrayDiapason:([III)Lkotlin/Triple;
      42: astore        5
      44: aload_0
      45: aload_1
      46: iload         4
      48: iconst_1
      49: iadd
      50: iload_3
      51: invokespecial #25                 // Method findMaxSubarrayDiapason:([III)Lkotlin/Triple;
      54: astore        6
      56: aload_0
      57: aload_1
      58: iload_2
      59: iload         4
      61: iload_3
      62: invokespecial #52                 // Method findMaxSubarrayCrosslines:([IIII)Lkotlin/Triple;
      65: astore        7
      67: aload         5
      69: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
      72: checkcast     #33                 // class java/lang/Number
      75: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      78: aload         6
      80: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
      83: checkcast     #33                 // class java/lang/Number
      86: invokevirtual #37                 // Method java/lang/Number.intValue:()I
      89: if_icmplt     122
      92: aload         5
      94: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
      97: checkcast     #33                 // class java/lang/Number
     100: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     103: aload         7
     105: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     108: checkcast     #33                 // class java/lang/Number
     111: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     114: if_icmplt     122
     117: aload         5
     119: goto          179
     122: aload         6
     124: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     127: checkcast     #33                 // class java/lang/Number
     130: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     133: aload         5
     135: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     138: checkcast     #33                 // class java/lang/Number
     141: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     144: if_icmplt     177
     147: aload         6
     149: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     152: checkcast     #33                 // class java/lang/Number
     155: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     158: aload         7
     160: invokevirtual #31                 // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     163: checkcast     #33                 // class java/lang/Number
     166: invokevirtual #37                 // Method java/lang/Number.intValue:()I
     169: if_icmplt     177
     172: aload         6
     174: goto          179
     177: aload         7
     179: areturn

  private final kotlin.Triple<java.lang.Integer, java.lang.Integer, java.lang.Integer> findMaxSubarrayCrosslines(int[], int, int, int);
    Code:
       0: ldc           #63                 // int -2147483648
       2: istore        5
       4: ldc           #63                 // int -2147483648
       6: istore        6
       8: iload_3
       9: istore        7
      11: iload_3
      12: iconst_1
      13: iadd
      14: istore        8
      16: iload_2
      17: iload         4
      19: if_icmpne     45
      22: new           #27                 // class kotlin/Triple
      25: dup
      26: iload_2
      27: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      30: iload         4
      32: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aload_1
      36: iload_2
      37: iaload
      38: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokespecial #48                 // Method kotlin/Triple."<init>":(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
      44: areturn
      45: iconst_0
      46: istore        9
      48: iload_3
      49: istore        10
      51: iload_2
      52: iload         10
      54: if_icmpgt     93
      57: iload         9
      59: aload_1
      60: iload         10
      62: iaload
      63: iadd
      64: istore        9
      66: iload         9
      68: iload         5
      70: if_icmple     81
      73: iload         10
      75: istore        7
      77: iload         9
      79: istore        5
      81: iload         10
      83: iload_2
      84: if_icmpeq     93
      87: iinc          10, -1
      90: goto          57
      93: iconst_0
      94: istore        9
      96: iload_3
      97: iconst_1
      98: iadd
      99: istore        10
     101: iload         10
     103: iload         4
     105: if_icmpgt     145
     108: iload         9
     110: aload_1
     111: iload         10
     113: iaload
     114: iadd
     115: istore        9
     117: iload         9
     119: iload         6
     121: if_icmple     132
     124: iload         10
     126: istore        8
     128: iload         9
     130: istore        6
     132: iload         10
     134: iload         4
     136: if_icmpeq     145
     139: iinc          10, 1
     142: goto          108
     145: new           #27                 // class kotlin/Triple
     148: dup
     149: iload         7
     151: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: iload         8
     156: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     159: iload         5
     161: iload         6
     163: iadd
     164: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     167: invokespecial #48                 // Method kotlin/Triple."<init>":(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
     170: areturn

  public Algorithms.MaxSubarraySum.DivideAndConquer$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #71                 // Method "<init>":()V
       4: return
}

Compiled from "DivideAndConquer.kt"
public final class Algorithms.MaxSubarraySum.DivideAndConquer {
  public static final Algorithms.MaxSubarraySum.DivideAndConquer$Companion Companion;

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

  static {};
    Code:
       0: new           #13                 // class Algorithms/MaxSubarraySum/DivideAndConquer$Companion
       3: dup
       4: aconst_null
       5: invokespecial #16                 // Method Algorithms/MaxSubarraySum/DivideAndConquer$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #20                 // Field Companion:LAlgorithms/MaxSubarraySum/DivideAndConquer$Companion;
      11: return
}


package befaster.solutions

sealed abstract class Item(open val price: Price)

object A : Item(50)
object B : Item(30)
object C : Item(20)
object D : Item(15)
object E : Item(40)
object Invalid : Item(-1)

typealias Basket = List<Item>
typealias Price = Int

interface Deal {
    val howManyYouNeedToBuy: Int
}
data class NAtPriceOf(val item: Item, override val howManyYouNeedToBuy: Int, val priceOf: Price): Deal {
    fun reducedPrice(numberOfItems: Int): Price {
        return (numberOfItems % howManyYouNeedToBuy) * item.price + (numberOfItems / howManyYouNeedToBuy) * priceOf
    }
}

data class BuyItemGetItemFree(
        val whatYouGetForFree: Item,
        val whatYouNeedToBuy: Item,
        override val howManyYouNeedToBuy: Int,
        val howManyYouGetForFree: Int) : Deal {

    fun reducedPrice(howManyYouHave: Int, howManyOfOther: Int): Price {
        val numberOfDiscounts = howManyOfOther / howManyYouNeedToBuy
        val result = ((howManyYouHave - numberOfDiscounts) * whatYouGetForFree.price)
        return Math.max(0, result)
    }

}
object NoDeal: Deal {
    override val howManyYouNeedToBuy: Int = 1
}

val offers = mapOf(
        A to listOf(NAtPriceOf(A, 3,130), NAtPriceOf(A, 5, 200)),
        B to listOf(BuyItemGetItemFree(B, E, 2, 1), NAtPriceOf(B, 2, 45))
)

class Checkout(basket: Basket) {
    companion object {
        fun priceFor(items: String): Price = Checkout(Scanner().getBasketFor(items)).total
    }

    val total: Price = if(basket.contains(Invalid)) -1 else {
        val groupedItems = basket.groupBy { it }
        val priceForItems = groupedItems.map { group ->
            val deals = offers[group.key] ?: listOf(NoDeal)
            val reducedPrice = getPriceFor(group.key, group.value.size, deals, groupedItems)
            reducedPrice.min()!!
        }.sum()
        priceForItems
    }

    fun getPriceFor(item: Item, numberOfItems: Int, deals: List<Deal>, group: Map<Item, List<Item>>): List<Int> {
        fun go(list: List<Item>): List<Int> {
            return when {
                list.isEmpty() -> listOf(0)
                else -> (listOf(numberOfItems) + deals.map { it.howManyYouNeedToBuy }).flatMap { howMany ->
                    deals.map {
                        when (it) {
                            is NAtPriceOf -> it.reducedPrice(howMany) + go(list.drop(howMany)).min()!!
                            is BuyItemGetItemFree -> it.reducedPrice(list.size, group[it.whatYouNeedToBuy].orEmpty().size) + go(list.drop(it.howManyYouNeedToBuy)).min()!!
                            else -> item.price * howMany + go(list.drop(howMany)).min()!!
                        }
                    }
                }
            }
        }
        return go(group[item].orEmpty())
    }

}

class Scanner {
    fun getBasketFor(itemsScanned: String): Basket = itemsScanned.map {
        when (it) {
            'A' -> A
            'B' -> B
            'C' -> C
            'D' -> D
            'E' -> E
            else -> Invalid
        }
    }

}

Compiled from "Item.kt"
public abstract class befaster.solutions.Item {
  private final int price;

  private befaster.solutions.Item(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field price:I
       9: return

  public int getPrice();
    Code:
       0: aload_0
       1: getfield      #13                 // Field price:I
       4: ireturn

  public befaster.solutions.Item(int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: iload_1
       2: invokespecial #20                 // Method "<init>":(I)V
       5: return
}

Compiled from "Item.kt"
public final class befaster.solutions.ItemKt {
  private static final java.util.Map<befaster.solutions.Item, java.util.List<befaster.solutions.Deal>> offers;

  public static final java.util.Map<befaster.solutions.Item, java.util.List<befaster.solutions.Deal>> getOffers();
    Code:
       0: getstatic     #12                 // Field offers:Ljava/util/Map;
       3: areturn

  static {};
    Code:
       0: iconst_2
       1: anewarray     #16                 // class kotlin/Pair
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #22                 // Field befaster/solutions/A.INSTANCE:Lbefaster/solutions/A;
      10: iconst_2
      11: anewarray     #24                 // class befaster/solutions/NAtPriceOf
      14: astore_1
      15: aload_1
      16: iconst_0
      17: new           #24                 // class befaster/solutions/NAtPriceOf
      20: dup
      21: getstatic     #22                 // Field befaster/solutions/A.INSTANCE:Lbefaster/solutions/A;
      24: checkcast     #26                 // class befaster/solutions/Item
      27: iconst_3
      28: sipush        130
      31: invokespecial #30                 // Method befaster/solutions/NAtPriceOf."<init>":(Lbefaster/solutions/Item;II)V
      34: aastore
      35: aload_1
      36: iconst_1
      37: new           #24                 // class befaster/solutions/NAtPriceOf
      40: dup
      41: getstatic     #22                 // Field befaster/solutions/A.INSTANCE:Lbefaster/solutions/A;
      44: checkcast     #26                 // class befaster/solutions/Item
      47: iconst_5
      48: sipush        200
      51: invokespecial #30                 // Method befaster/solutions/NAtPriceOf."<init>":(Lbefaster/solutions/Item;II)V
      54: aastore
      55: aload_1
      56: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      59: invokestatic  #42                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      62: aastore
      63: aload_0
      64: iconst_1
      65: getstatic     #47                 // Field befaster/solutions/B.INSTANCE:Lbefaster/solutions/B;
      68: iconst_2
      69: anewarray     #49                 // class befaster/solutions/Deal
      72: astore_1
      73: aload_1
      74: iconst_0
      75: new           #51                 // class befaster/solutions/BuyItemGetItemFree
      78: dup
      79: getstatic     #47                 // Field befaster/solutions/B.INSTANCE:Lbefaster/solutions/B;
      82: checkcast     #26                 // class befaster/solutions/Item
      85: getstatic     #56                 // Field befaster/solutions/E.INSTANCE:Lbefaster/solutions/E;
      88: checkcast     #26                 // class befaster/solutions/Item
      91: iconst_2
      92: iconst_1
      93: invokespecial #59                 // Method befaster/solutions/BuyItemGetItemFree."<init>":(Lbefaster/solutions/Item;Lbefaster/solutions/Item;II)V
      96: aastore
      97: aload_1
      98: iconst_1
      99: new           #24                 // class befaster/solutions/NAtPriceOf
     102: dup
     103: getstatic     #47                 // Field befaster/solutions/B.INSTANCE:Lbefaster/solutions/B;
     106: checkcast     #26                 // class befaster/solutions/Item
     109: iconst_2
     110: bipush        45
     112: invokespecial #30                 // Method befaster/solutions/NAtPriceOf."<init>":(Lbefaster/solutions/Item;II)V
     115: aastore
     116: aload_1
     117: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     120: invokestatic  #42                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     123: aastore
     124: aload_0
     125: invokestatic  #65                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     128: putstatic     #12                 // Field offers:Ljava/util/Map;
     131: return
}


package day04

import java.io.File

fun main() {

    fun part1(input: String) : Long {
        val data = input.split("\n").sumOf { line ->
            val parts = line.split(",")
            val firstPart = parts[0].split("-")
            val secondPart = parts[1].split("-")
            val firstStart = firstPart.first().toInt()
            val firstEnd = firstPart.last().toInt()
            val secondStart = secondPart.first().toInt()
            val secondEnd = secondPart.last().toInt()
            when {
                firstStart <= secondStart && firstEnd >= secondEnd -> 1L
                firstStart >= secondStart && firstEnd <= secondEnd -> 1L
                else -> 0L
            }
        }
        return data
    }

    fun part2(input: String) : Long {
        val data = input.split("\n").sumOf { line ->
            val parts = line.split(",")
            val firstPart = parts[0].split("-")
            val secondPart = parts[1].split("-")
            val firstStart = firstPart.first().toInt()
            val firstEnd = firstPart.last().toInt()
            val secondStart = secondPart.first().toInt()
            val secondEnd = secondPart.last().toInt()
            when {
                secondEnd < firstStart -> 0L
                firstEnd < secondStart -> 0L
                else -> 1L
            }
        }
        return data
    }

    val testInput = File("src/day04/Day04_test.txt").readText()
    println(part1(testInput))
    println(part2(testInput))
    check(part1(testInput) == 2L)
    check(part2(testInput) == 4L)

    val input = File("src/day04/Day04.txt").readText()
    println(part1(input))
    println(part2(input))

}

Compiled from "Day04.kt"
public final class day04.Day04Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day04/Day04_test.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: astore_0
      16: aload_0
      17: invokestatic  #24                 // Method main$part1:(Ljava/lang/String;)J
      20: lstore_1
      21: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: lload_1
      25: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
      28: aload_0
      29: invokestatic  #39                 // Method main$part2:(Ljava/lang/String;)J
      32: lstore_1
      33: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: lload_1
      37: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
      40: aload_0
      41: invokestatic  #24                 // Method main$part1:(Ljava/lang/String;)J
      44: ldc2_w        #40                 // long 2l
      47: lcmp
      48: ifne          55
      51: iconst_1
      52: goto          56
      55: iconst_0
      56: ifne          69
      59: new           #43                 // class java/lang/IllegalStateException
      62: dup
      63: ldc           #45                 // String Check failed.
      65: invokespecial #46                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      68: athrow
      69: aload_0
      70: invokestatic  #39                 // Method main$part2:(Ljava/lang/String;)J
      73: ldc2_w        #47                 // long 4l
      76: lcmp
      77: ifne          84
      80: iconst_1
      81: goto          85
      84: iconst_0
      85: ifne          98
      88: new           #43                 // class java/lang/IllegalStateException
      91: dup
      92: ldc           #45                 // String Check failed.
      94: invokespecial #46                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      97: athrow
      98: new           #8                  // class java/io/File
     101: dup
     102: ldc           #50                 // String src/day04/Day04.txt
     104: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     107: aconst_null
     108: iconst_1
     109: aconst_null
     110: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
     113: astore_1
     114: aload_1
     115: invokestatic  #24                 // Method main$part1:(Ljava/lang/String;)J
     118: lstore_2
     119: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
     122: lload_2
     123: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
     126: aload_1
     127: invokestatic  #39                 // Method main$part2:(Ljava/lang/String;)J
     130: lstore_2
     131: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
     134: lload_2
     135: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
     138: return

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

  private static final long main$part1(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #62                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #55                 // class java/lang/String
       8: astore_3
       9: aload_3
      10: iconst_0
      11: ldc           #64                 // String \n
      13: aastore
      14: aload_3
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #72                 // class java/lang/Iterable
      26: astore_3
      27: lconst_0
      28: lstore        4
      30: aload_3
      31: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          273
      48: aload         6
      50: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: lload         4
      59: aload         7
      61: checkcast     #55                 // class java/lang/String
      64: astore        8
      66: lstore        17
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #62                 // class java/lang/CharSequence
      76: iconst_1
      77: anewarray     #55                 // class java/lang/String
      80: astore        10
      82: aload         10
      84: iconst_0
      85: ldc           #88                 // String ,
      87: aastore
      88: aload         10
      90: iconst_0
      91: iconst_0
      92: bipush        6
      94: aconst_null
      95: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      98: astore        11
     100: aload         11
     102: iconst_0
     103: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     108: checkcast     #62                 // class java/lang/CharSequence
     111: iconst_1
     112: anewarray     #55                 // class java/lang/String
     115: astore        12
     117: aload         12
     119: iconst_0
     120: ldc           #96                 // String -
     122: aastore
     123: aload         12
     125: iconst_0
     126: iconst_0
     127: bipush        6
     129: aconst_null
     130: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     133: astore        10
     135: aload         11
     137: iconst_1
     138: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     143: checkcast     #62                 // class java/lang/CharSequence
     146: iconst_1
     147: anewarray     #55                 // class java/lang/String
     150: astore        13
     152: aload         13
     154: iconst_0
     155: ldc           #96                 // String -
     157: aastore
     158: aload         13
     160: iconst_0
     161: iconst_0
     162: bipush        6
     164: aconst_null
     165: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     168: astore        12
     170: aload         10
     172: invokestatic  #102                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     175: checkcast     #55                 // class java/lang/String
     178: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     181: istore        13
     183: aload         10
     185: invokestatic  #111                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     188: checkcast     #55                 // class java/lang/String
     191: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     194: istore        14
     196: aload         12
     198: invokestatic  #102                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     201: checkcast     #55                 // class java/lang/String
     204: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     207: istore        15
     209: aload         12
     211: invokestatic  #111                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     214: checkcast     #55                 // class java/lang/String
     217: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     220: istore        16
     222: nop
     223: iload         13
     225: iload         15
     227: if_icmpgt     241
     230: iload         14
     232: iload         16
     234: if_icmplt     241
     237: lconst_1
     238: goto          260
     241: iload         13
     243: iload         15
     245: if_icmplt     259
     248: iload         14
     250: iload         16
     252: if_icmpgt     259
     255: lconst_1
     256: goto          260
     259: lconst_0
     260: nop
     261: lstore        19
     263: lload         17
     265: lload         19
     267: ladd
     268: lstore        4
     270: goto          38
     273: lload         4
     275: lstore_1
     276: lload_1
     277: lreturn

  private static final long main$part2(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #62                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #55                 // class java/lang/String
       8: astore_3
       9: aload_3
      10: iconst_0
      11: ldc           #64                 // String \n
      13: aastore
      14: aload_3
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #72                 // class java/lang/Iterable
      26: astore_3
      27: lconst_0
      28: lstore        4
      30: aload_3
      31: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          259
      48: aload         6
      50: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: lload         4
      59: aload         7
      61: checkcast     #55                 // class java/lang/String
      64: astore        8
      66: lstore        17
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #62                 // class java/lang/CharSequence
      76: iconst_1
      77: anewarray     #55                 // class java/lang/String
      80: astore        10
      82: aload         10
      84: iconst_0
      85: ldc           #88                 // String ,
      87: aastore
      88: aload         10
      90: iconst_0
      91: iconst_0
      92: bipush        6
      94: aconst_null
      95: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      98: astore        11
     100: aload         11
     102: iconst_0
     103: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     108: checkcast     #62                 // class java/lang/CharSequence
     111: iconst_1
     112: anewarray     #55                 // class java/lang/String
     115: astore        12
     117: aload         12
     119: iconst_0
     120: ldc           #96                 // String -
     122: aastore
     123: aload         12
     125: iconst_0
     126: iconst_0
     127: bipush        6
     129: aconst_null
     130: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     133: astore        10
     135: aload         11
     137: iconst_1
     138: invokeinterface #94,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     143: checkcast     #62                 // class java/lang/CharSequence
     146: iconst_1
     147: anewarray     #55                 // class java/lang/String
     150: astore        13
     152: aload         13
     154: iconst_0
     155: ldc           #96                 // String -
     157: aastore
     158: aload         13
     160: iconst_0
     161: iconst_0
     162: bipush        6
     164: aconst_null
     165: invokestatic  #70                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     168: astore        12
     170: aload         10
     172: invokestatic  #102                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     175: checkcast     #55                 // class java/lang/String
     178: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     181: istore        13
     183: aload         10
     185: invokestatic  #111                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     188: checkcast     #55                 // class java/lang/String
     191: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     194: istore        14
     196: aload         12
     198: invokestatic  #102                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     201: checkcast     #55                 // class java/lang/String
     204: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     207: istore        15
     209: aload         12
     211: invokestatic  #111                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     214: checkcast     #55                 // class java/lang/String
     217: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     220: istore        16
     222: nop
     223: iload         16
     225: iload         13
     227: if_icmpge     234
     230: lconst_0
     231: goto          246
     234: iload         14
     236: iload         15
     238: if_icmpge     245
     241: lconst_0
     242: goto          246
     245: lconst_1
     246: nop
     247: lstore        19
     249: lload         17
     251: lload         19
     253: ladd
     254: lstore        4
     256: goto          38
     259: lload         4
     261: lstore_1
     262: lload_1
     263: lreturn
}


package day03

import java.io.File

fun main() {
    val letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    fun part1(input: String) : Int {
        val data = input.split("\n")
        var sum = 0
        for (line in data) {
            val secondHalf = line.substring(line.length/2)
            for (char in line){
                if (secondHalf.contains(char, false)){
                    sum += letters.indexOf(char) + 1
                    break
                }
            }
        }
        return sum
    }

    fun part2(input: String) : Int {
        val data = input.split("\n").chunked(3)
        var sum = 0
        for (group in data){
            val firstSet = mutableSetOf<Char>()
            val secondSet = mutableSetOf<Char>()
            val thirdSet = mutableSetOf<Char>()
            var setNum = 1
            val groupAll = group.joinToString(",")
            for (char in groupAll){
                if (char == ','){
                    setNum++
                    continue
                }
                when (setNum) {
                    1 -> firstSet.add(char)
                    2 -> secondSet.add(char)
                    else -> thirdSet.add(char)
                }
            }
            for (char in firstSet){
                if (secondSet.contains(char) && thirdSet.contains(char)){
                    sum += letters.indexOf(char) + 1
                    break
                }
            }
        }
        return sum
    }

    val testInput = File("src/day03/Day03_test.txt").readText()
    println(part1(testInput))
    println(part2(testInput))
    check(part1(testInput) == 157)
    check(part2(testInput) == 70)

    val input = File("src/day03/Day03.txt").readText()
    println(part1(input))
    println(part2(input))

}

Compiled from "Day03.kt"
public final class day03.Day03Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
       2: astore_0
       3: new           #10                 // class java/io/File
       6: dup
       7: ldc           #12                 // String src/day03/Day03_test.txt
       9: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      12: aconst_null
      13: iconst_1
      14: aconst_null
      15: invokestatic  #22                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      18: astore_1
      19: aload_0
      20: aload_1
      21: invokestatic  #26                 // Method main$part1:(Ljava/lang/String;Ljava/lang/String;)I
      24: istore_2
      25: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: iload_2
      29: invokevirtual #38                 // Method java/io/PrintStream.println:(I)V
      32: aload_0
      33: aload_1
      34: invokestatic  #41                 // Method main$part2:(Ljava/lang/String;Ljava/lang/String;)I
      37: istore_2
      38: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
      41: iload_2
      42: invokevirtual #38                 // Method java/io/PrintStream.println:(I)V
      45: aload_0
      46: aload_1
      47: invokestatic  #26                 // Method main$part1:(Ljava/lang/String;Ljava/lang/String;)I
      50: sipush        157
      53: if_icmpne     60
      56: iconst_1
      57: goto          61
      60: iconst_0
      61: ifne          74
      64: new           #43                 // class java/lang/IllegalStateException
      67: dup
      68: ldc           #45                 // String Check failed.
      70: invokespecial #46                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      73: athrow
      74: aload_0
      75: aload_1
      76: invokestatic  #41                 // Method main$part2:(Ljava/lang/String;Ljava/lang/String;)I
      79: bipush        70
      81: if_icmpne     88
      84: iconst_1
      85: goto          89
      88: iconst_0
      89: ifne          102
      92: new           #43                 // class java/lang/IllegalStateException
      95: dup
      96: ldc           #45                 // String Check failed.
      98: invokespecial #46                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     101: athrow
     102: new           #10                 // class java/io/File
     105: dup
     106: ldc           #48                 // String src/day03/Day03.txt
     108: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     111: aconst_null
     112: iconst_1
     113: aconst_null
     114: invokestatic  #22                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
     117: astore_2
     118: aload_0
     119: aload_2
     120: invokestatic  #26                 // Method main$part1:(Ljava/lang/String;Ljava/lang/String;)I
     123: istore_3
     124: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     127: iload_3
     128: invokevirtual #38                 // Method java/io/PrintStream.println:(I)V
     131: aload_0
     132: aload_2
     133: invokestatic  #41                 // Method main$part2:(Ljava/lang/String;Ljava/lang/String;)I
     136: istore_3
     137: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     140: iload_3
     141: invokevirtual #38                 // Method java/io/PrintStream.println:(I)V
     144: return

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

  private static final int main$part1(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #61                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #54                 // class java/lang/String
       8: astore_3
       9: aload_3
      10: iconst_0
      11: ldc           #63                 // String \n
      13: aastore
      14: aload_3
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #69                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: invokeinterface #75,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      32: astore        4
      34: aload         4
      36: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          144
      44: aload         4
      46: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: checkcast     #54                 // class java/lang/String
      54: astore        5
      56: aload         5
      58: aload         5
      60: invokevirtual #89                 // Method java/lang/String.length:()I
      63: iconst_2
      64: idiv
      65: invokevirtual #93                 // Method java/lang/String.substring:(I)Ljava/lang/String;
      68: dup
      69: ldc           #95                 // String substring(...)
      71: invokestatic  #101                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      74: astore        6
      76: iconst_0
      77: istore        7
      79: aload         5
      81: invokevirtual #89                 // Method java/lang/String.length:()I
      84: istore        8
      86: iload         7
      88: iload         8
      90: if_icmpge     34
      93: aload         5
      95: iload         7
      97: invokevirtual #105                // Method java/lang/String.charAt:(I)C
     100: istore        9
     102: aload         6
     104: checkcast     #61                 // class java/lang/CharSequence
     107: iload         9
     109: iconst_0
     110: invokestatic  #109                // Method kotlin/text/StringsKt.contains:(Ljava/lang/CharSequence;CZ)Z
     113: ifeq          138
     116: iload_3
     117: aload_0
     118: checkcast     #61                 // class java/lang/CharSequence
     121: iload         9
     123: iconst_0
     124: iconst_0
     125: bipush        6
     127: aconst_null
     128: invokestatic  #113                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
     131: iconst_1
     132: iadd
     133: iadd
     134: istore_3
     135: goto          34
     138: iinc          7, 1
     141: goto          86
     144: iload_3
     145: ireturn

  private static final int main$part2(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #61                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #54                 // class java/lang/String
       8: astore_3
       9: aload_3
      10: iconst_0
      11: ldc           #63                 // String \n
      13: aastore
      14: aload_3
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #69                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #123                // class java/lang/Iterable
      26: iconst_3
      27: invokestatic  #129                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      30: astore_2
      31: iconst_0
      32: istore_3
      33: aload_2
      34: invokeinterface #75,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      39: astore        4
      41: aload         4
      43: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          323
      51: aload         4
      53: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: checkcast     #71                 // class java/util/List
      61: astore        5
      63: new           #131                // class java/util/LinkedHashSet
      66: dup
      67: invokespecial #133                // Method java/util/LinkedHashSet."<init>":()V
      70: checkcast     #135                // class java/util/Set
      73: astore        6
      75: new           #131                // class java/util/LinkedHashSet
      78: dup
      79: invokespecial #133                // Method java/util/LinkedHashSet."<init>":()V
      82: checkcast     #135                // class java/util/Set
      85: astore        7
      87: new           #131                // class java/util/LinkedHashSet
      90: dup
      91: invokespecial #133                // Method java/util/LinkedHashSet."<init>":()V
      94: checkcast     #135                // class java/util/Set
      97: astore        8
      99: iconst_1
     100: istore        9
     102: aload         5
     104: checkcast     #123                // class java/lang/Iterable
     107: ldc           #137                // String ,
     109: checkcast     #61                 // class java/lang/CharSequence
     112: aconst_null
     113: aconst_null
     114: iconst_0
     115: aconst_null
     116: aconst_null
     117: bipush        62
     119: aconst_null
     120: invokestatic  #141                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     123: astore        10
     125: iconst_0
     126: istore        11
     128: aload         10
     130: invokevirtual #89                 // Method java/lang/String.length:()I
     133: istore        12
     135: iload         11
     137: iload         12
     139: if_icmpge     237
     142: aload         10
     144: iload         11
     146: invokevirtual #105                // Method java/lang/String.charAt:(I)C
     149: istore        13
     151: iload         13
     153: bipush        44
     155: if_icmpne     164
     158: iinc          9, 1
     161: goto          231
     164: iload         9
     166: tableswitch   { // 1 to 2
                     1: 188
                     2: 203
               default: 218
          }
     188: aload         6
     190: iload         13
     192: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     195: invokeinterface #151,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     200: goto          230
     203: aload         7
     205: iload         13
     207: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     210: invokeinterface #151,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     215: goto          230
     218: aload         8
     220: iload         13
     222: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     225: invokeinterface #151,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     230: pop
     231: iinc          11, 1
     234: goto          135
     237: aload         6
     239: invokeinterface #152,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     244: astore        11
     246: aload         11
     248: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     253: ifeq          41
     256: aload         11
     258: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     263: checkcast     #143                // class java/lang/Character
     266: invokevirtual #156                // Method java/lang/Character.charValue:()C
     269: istore        12
     271: aload         7
     273: iload         12
     275: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     278: invokeinterface #158,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     283: ifeq          246
     286: aload         8
     288: iload         12
     290: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     293: invokeinterface #158,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     298: ifeq          246
     301: iload_3
     302: aload_0
     303: checkcast     #61                 // class java/lang/CharSequence
     306: iload         12
     308: iconst_0
     309: iconst_0
     310: bipush        6
     312: aconst_null
     313: invokestatic  #113                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
     316: iconst_1
     317: iadd
     318: iadd
     319: istore_3
     320: goto          41
     323: iload_3
     324: ireturn
}


package day02

import java.io.File

fun main() {

    fun part1(input: String) : Long {
        val lostSet = setOf("A Z", "B X", "C Y")
        val winSet = setOf("A Y", "B Z", "C X")
        val drawSet = setOf("A X", "B Y", "C Z")

        val scoreMap = mapOf('X' to 1, 'Y' to 2, 'Z' to 3)

        val data = input.split("\n").sumOf {
            val gameScore = when(it){
                in lostSet -> 0L
                in drawSet -> 3L
                in winSet -> 6L
                else -> throw IllegalArgumentException()
            }
            gameScore + scoreMap.getOrDefault(it.last(), 0)
        }
        return data
    }

    fun part2(input: String) : Long {
        val winSet = setOf("A B", "B C", "C A")
        val lostSet = setOf("A C", "B A", "C B")
        val drawSet = setOf("A A", "B B", "C C")

        val scoreMap = mapOf('A' to 1, 'B' to 2, 'C' to 3)

        val data = input.split("\n").sumOf { game ->
            val (gameScore, myScore) = when(game.last()){
                'X' -> 0L to scoreMap.getOrDefault(lostSet.first { it.first() == game.first() }.last(), 0)
                'Y' -> 3L to scoreMap.getOrDefault(drawSet.first { it.first() == game.first() }.last(), 0)
                'Z' -> 6L to scoreMap.getOrDefault(winSet.first { it.first() == game.first() }.last(), 0)
                else -> throw IllegalArgumentException()
            }
            gameScore + myScore
        }
        return data
    }

    val testInput = File("src/day02/Day02_test.txt").readText()
    println(part2(testInput))
    check(part2(testInput) == 12L)

    val input = File("src/day02/Day02.txt").readText()
    println(part1(input))
    println(part2(input))

}

Compiled from "Day02.kt"
public final class day02.Day02Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day02/Day02_test.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: astore_0
      16: aload_0
      17: invokestatic  #24                 // Method main$part2:(Ljava/lang/String;)J
      20: lstore_1
      21: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: lload_1
      25: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
      28: aload_0
      29: invokestatic  #24                 // Method main$part2:(Ljava/lang/String;)J
      32: ldc2_w        #37                 // long 12l
      35: lcmp
      36: ifne          43
      39: iconst_1
      40: goto          44
      43: iconst_0
      44: ifne          57
      47: new           #40                 // class java/lang/IllegalStateException
      50: dup
      51: ldc           #42                 // String Check failed.
      53: invokespecial #43                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      56: athrow
      57: new           #8                  // class java/io/File
      60: dup
      61: ldc           #45                 // String src/day02/Day02.txt
      63: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      66: aconst_null
      67: iconst_1
      68: aconst_null
      69: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      72: astore_1
      73: aload_1
      74: invokestatic  #48                 // Method main$part1:(Ljava/lang/String;)J
      77: lstore_2
      78: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      81: lload_2
      82: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
      85: aload_1
      86: invokestatic  #24                 // Method main$part2:(Ljava/lang/String;)J
      89: lstore_2
      90: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      93: lload_2
      94: invokevirtual #36                 // Method java/io/PrintStream.println:(J)V
      97: return

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

  private static final long main$part1(java.lang.String);
    Code:
       0: iconst_3
       1: anewarray     #53                 // class java/lang/String
       4: astore_2
       5: aload_2
       6: iconst_0
       7: ldc           #60                 // String A Z
       9: aastore
      10: aload_2
      11: iconst_1
      12: ldc           #62                 // String B X
      14: aastore
      15: aload_2
      16: iconst_2
      17: ldc           #64                 // String C Y
      19: aastore
      20: aload_2
      21: invokestatic  #70                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      24: astore_1
      25: iconst_3
      26: anewarray     #53                 // class java/lang/String
      29: astore_3
      30: aload_3
      31: iconst_0
      32: ldc           #72                 // String A Y
      34: aastore
      35: aload_3
      36: iconst_1
      37: ldc           #74                 // String B Z
      39: aastore
      40: aload_3
      41: iconst_2
      42: ldc           #76                 // String C X
      44: aastore
      45: aload_3
      46: invokestatic  #70                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      49: astore_2
      50: iconst_3
      51: anewarray     #53                 // class java/lang/String
      54: astore        4
      56: aload         4
      58: iconst_0
      59: ldc           #78                 // String A X
      61: aastore
      62: aload         4
      64: iconst_1
      65: ldc           #80                 // String B Y
      67: aastore
      68: aload         4
      70: iconst_2
      71: ldc           #82                 // String C Z
      73: aastore
      74: aload         4
      76: invokestatic  #70                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      79: astore_3
      80: iconst_3
      81: anewarray     #84                 // class kotlin/Pair
      84: astore        5
      86: aload         5
      88: iconst_0
      89: bipush        88
      91: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      94: iconst_1
      95: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     101: aastore
     102: aload         5
     104: iconst_1
     105: bipush        89
     107: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     110: iconst_2
     111: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     117: aastore
     118: aload         5
     120: iconst_2
     121: bipush        90
     123: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     126: iconst_3
     127: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     133: aastore
     134: aload         5
     136: invokestatic  #107                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     139: astore        4
     141: aload_0
     142: checkcast     #109                // class java/lang/CharSequence
     145: iconst_1
     146: anewarray     #53                 // class java/lang/String
     149: astore        7
     151: aload         7
     153: iconst_0
     154: ldc           #111                // String \n
     156: aastore
     157: aload         7
     159: iconst_0
     160: iconst_0
     161: bipush        6
     163: aconst_null
     164: invokestatic  #117                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     167: checkcast     #119                // class java/lang/Iterable
     170: astore        7
     172: lconst_0
     173: lstore        8
     175: aload         7
     177: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     182: astore        10
     184: aload         10
     186: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     191: ifeq          323
     194: aload         10
     196: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     201: astore        11
     203: lload         8
     205: aload         11
     207: checkcast     #53                 // class java/lang/String
     210: astore        12
     212: lstore        17
     214: iconst_0
     215: istore        13
     217: aload         12
     219: astore        14
     221: aload_1
     222: aload         14
     224: invokeinterface #139,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     229: ifeq          236
     232: lconst_0
     233: goto          278
     236: aload_3
     237: aload         14
     239: invokeinterface #139,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     244: ifeq          253
     247: ldc2_w        #140                // long 3l
     250: goto          278
     253: aload_2
     254: aload         14
     256: invokeinterface #139,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     261: ifeq          270
     264: ldc2_w        #142                // long 6l
     267: goto          278
     270: new           #145                // class java/lang/IllegalArgumentException
     273: dup
     274: invokespecial #147                // Method java/lang/IllegalArgumentException."<init>":()V
     277: athrow
     278: lstore        15
     280: lload         15
     282: aload         4
     284: aload         12
     286: checkcast     #109                // class java/lang/CharSequence
     289: invokestatic  #151                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     292: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     295: iconst_0
     296: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     299: invokeinterface #157,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     304: checkcast     #159                // class java/lang/Number
     307: invokevirtual #163                // Method java/lang/Number.longValue:()J
     310: ladd
     311: lstore        19
     313: lload         17
     315: lload         19
     317: ladd
     318: lstore        8
     320: goto          184
     323: lload         8
     325: lstore        5
     327: lload         5
     329: lreturn

  private static final long main$part2(java.lang.String);
    Code:
       0: iconst_3
       1: anewarray     #53                 // class java/lang/String
       4: astore_2
       5: aload_2
       6: iconst_0
       7: ldc           #179                // String A B
       9: aastore
      10: aload_2
      11: iconst_1
      12: ldc           #181                // String B C
      14: aastore
      15: aload_2
      16: iconst_2
      17: ldc           #183                // String C A
      19: aastore
      20: aload_2
      21: invokestatic  #70                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      24: astore_1
      25: iconst_3
      26: anewarray     #53                 // class java/lang/String
      29: astore_3
      30: aload_3
      31: iconst_0
      32: ldc           #185                // String A C
      34: aastore
      35: aload_3
      36: iconst_1
      37: ldc           #187                // String B A
      39: aastore
      40: aload_3
      41: iconst_2
      42: ldc           #189                // String C B
      44: aastore
      45: aload_3
      46: invokestatic  #70                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      49: astore_2
      50: iconst_3
      51: anewarray     #53                 // class java/lang/String
      54: astore        4
      56: aload         4
      58: iconst_0
      59: ldc           #191                // String A A
      61: aastore
      62: aload         4
      64: iconst_1
      65: ldc           #193                // String B B
      67: aastore
      68: aload         4
      70: iconst_2
      71: ldc           #195                // String C C
      73: aastore
      74: aload         4
      76: invokestatic  #70                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      79: astore_3
      80: iconst_3
      81: anewarray     #84                 // class kotlin/Pair
      84: astore        5
      86: aload         5
      88: iconst_0
      89: bipush        65
      91: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      94: iconst_1
      95: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     101: aastore
     102: aload         5
     104: iconst_1
     105: bipush        66
     107: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     110: iconst_2
     111: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     117: aastore
     118: aload         5
     120: iconst_2
     121: bipush        67
     123: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     126: iconst_3
     127: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     133: aastore
     134: aload         5
     136: invokestatic  #107                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     139: astore        4
     141: aload_0
     142: checkcast     #109                // class java/lang/CharSequence
     145: iconst_1
     146: anewarray     #53                 // class java/lang/String
     149: astore        7
     151: aload         7
     153: iconst_0
     154: ldc           #111                // String \n
     156: aastore
     157: aload         7
     159: iconst_0
     160: iconst_0
     161: bipush        6
     163: aconst_null
     164: invokestatic  #117                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     167: checkcast     #119                // class java/lang/Iterable
     170: astore        7
     172: lconst_0
     173: lstore        8
     175: aload         7
     177: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     182: astore        10
     184: aload         10
     186: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     191: ifeq          703
     194: aload         10
     196: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     201: astore        11
     203: lload         8
     205: aload         11
     207: checkcast     #53                 // class java/lang/String
     210: astore        12
     212: lstore        26
     214: iconst_0
     215: istore        13
     217: aload         12
     219: checkcast     #109                // class java/lang/CharSequence
     222: invokestatic  #151                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     225: tableswitch   { // 88 to 90
                    88: 252
                    89: 383
                    90: 516
               default: 649
          }
     252: lconst_0
     253: invokestatic  #200                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     256: aload         4
     258: aload_2
     259: checkcast     #119                // class java/lang/Iterable
     262: astore        14
     264: astore        15
     266: astore        16
     268: iconst_0
     269: istore        17
     271: aload         14
     273: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     278: astore        18
     280: aload         18
     282: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     287: ifeq          341
     290: aload         18
     292: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     297: astore        19
     299: aload         19
     301: checkcast     #53                 // class java/lang/String
     304: astore        20
     306: iconst_0
     307: istore        21
     309: aload         20
     311: checkcast     #109                // class java/lang/CharSequence
     314: invokestatic  #203                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     317: aload         12
     319: checkcast     #109                // class java/lang/CharSequence
     322: invokestatic  #203                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     325: if_icmpne     332
     328: iconst_1
     329: goto          333
     332: iconst_0
     333: ifeq          280
     336: aload         19
     338: goto          351
     341: new           #205                // class java/util/NoSuchElementException
     344: dup
     345: ldc           #207                // String Collection contains no element matching the predicate.
     347: invokespecial #208                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     350: athrow
     351: astore        22
     353: aload         16
     355: aload         15
     357: aload         22
     359: checkcast     #109                // class java/lang/CharSequence
     362: invokestatic  #151                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     365: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     368: iconst_0
     369: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     372: invokeinterface #157,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     377: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     380: goto          657
     383: ldc2_w        #140                // long 3l
     386: invokestatic  #200                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     389: aload         4
     391: aload_3
     392: checkcast     #119                // class java/lang/Iterable
     395: astore        14
     397: astore        15
     399: astore        16
     401: iconst_0
     402: istore        17
     404: aload         14
     406: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     411: astore        18
     413: aload         18
     415: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     420: ifeq          474
     423: aload         18
     425: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     430: astore        19
     432: aload         19
     434: checkcast     #53                 // class java/lang/String
     437: astore        20
     439: iconst_0
     440: istore        21
     442: aload         20
     444: checkcast     #109                // class java/lang/CharSequence
     447: invokestatic  #203                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     450: aload         12
     452: checkcast     #109                // class java/lang/CharSequence
     455: invokestatic  #203                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     458: if_icmpne     465
     461: iconst_1
     462: goto          466
     465: iconst_0
     466: ifeq          413
     469: aload         19
     471: goto          484
     474: new           #205                // class java/util/NoSuchElementException
     477: dup
     478: ldc           #207                // String Collection contains no element matching the predicate.
     480: invokespecial #208                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     483: athrow
     484: astore        22
     486: aload         16
     488: aload         15
     490: aload         22
     492: checkcast     #109                // class java/lang/CharSequence
     495: invokestatic  #151                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     498: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     501: iconst_0
     502: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     505: invokeinterface #157,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     510: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     513: goto          657
     516: ldc2_w        #142                // long 6l
     519: invokestatic  #200                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     522: aload         4
     524: aload_1
     525: checkcast     #119                // class java/lang/Iterable
     528: astore        14
     530: astore        15
     532: astore        16
     534: iconst_0
     535: istore        17
     537: aload         14
     539: invokeinterface #123,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     544: astore        18
     546: aload         18
     548: invokeinterface #129,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     553: ifeq          607
     556: aload         18
     558: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     563: astore        19
     565: aload         19
     567: checkcast     #53                 // class java/lang/String
     570: astore        20
     572: iconst_0
     573: istore        21
     575: aload         20
     577: checkcast     #109                // class java/lang/CharSequence
     580: invokestatic  #203                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     583: aload         12
     585: checkcast     #109                // class java/lang/CharSequence
     588: invokestatic  #203                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     591: if_icmpne     598
     594: iconst_1
     595: goto          599
     598: iconst_0
     599: ifeq          546
     602: aload         19
     604: goto          617
     607: new           #205                // class java/util/NoSuchElementException
     610: dup
     611: ldc           #207                // String Collection contains no element matching the predicate.
     613: invokespecial #208                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     616: athrow
     617: astore        22
     619: aload         16
     621: aload         15
     623: aload         22
     625: checkcast     #109                // class java/lang/CharSequence
     628: invokestatic  #151                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     631: invokestatic  #90                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     634: iconst_0
     635: invokestatic  #95                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     638: invokeinterface #157,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     643: invokestatic  #101                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     646: goto          657
     649: new           #145                // class java/lang/IllegalArgumentException
     652: dup
     653: invokespecial #147                // Method java/lang/IllegalArgumentException."<init>":()V
     656: athrow
     657: astore        23
     659: aload         23
     661: invokevirtual #211                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     664: checkcast     #159                // class java/lang/Number
     667: invokevirtual #163                // Method java/lang/Number.longValue:()J
     670: lstore        24
     672: aload         23
     674: invokevirtual #214                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     677: checkcast     #159                // class java/lang/Number
     680: invokevirtual #218                // Method java/lang/Number.intValue:()I
     683: istore        17
     685: lload         24
     687: iload         17
     689: i2l
     690: ladd
     691: lstore        28
     693: lload         26
     695: lload         28
     697: ladd
     698: lstore        8
     700: goto          184
     703: lload         8
     705: lstore        5
     707: lload         5
     709: lreturn
}