package com.morninghacks.aoc2017

import java.lang.invoke.MethodHandles

/*
You receive a signal directly from the CPU. Because of your recent assistance with jump instructions, it would like you to compute the result of a series of unusual register instructions.

Each instruction consists of several parts: the register to modify, whether to increase or decrease that register's value, the amount by which to increase or decrease it, and a condition. If the condition fails, skip the instruction without modifying the register. The registers all start at 0. The instructions look like this:

b inc 5 if a > 1
a inc 1 if b < 5
c dec -10 if a >= 1
c inc -20 if c == 10

These instructions would be processed as follows:

    Because a starts at 0, it is not greater than 1, and so b is not modified.
    a is increased by 1 (to 1) because b is less than 5 (it is 0).
    c is decreased by -10 (to 10) because a is now greater than or equal to 1 (it is 1).
    c is increased by -20 (to -10) because c is equal to 10.

After this process, the largest value in any register is 1.

You might also encounter <= (less than or equal to) or != (not equal to). However, the CPU doesn't have the bandwidth to tell you what all the registers are named, and leaves that to you to determine.

What is the largest value in any register after completing the instructions in your puzzle input?
 */
sealed class ComparisonOperator {
    abstract fun apply(lhs: Int, rhs: Int): Boolean
}

object LessThan : ComparisonOperator() {
    override fun apply(lhs: Int, rhs: Int) = lhs < rhs
}

object LessThanOrEqualTo : ComparisonOperator() {
    override fun apply(lhs: Int, rhs: Int) = lhs <= rhs
}

object GreaterThan : ComparisonOperator() {
    override fun apply(lhs: Int, rhs: Int) = lhs > rhs
}

object GreaterThanOrEqualTo : ComparisonOperator() {
    override fun apply(lhs: Int, rhs: Int) = lhs >= rhs
}

object EqualTo : ComparisonOperator() {
    override fun apply(lhs: Int, rhs: Int) = lhs == rhs
}

object NotEqualTo : ComparisonOperator() {
    override fun apply(lhs: Int, rhs: Int) = lhs != rhs
}

data class Instruction(val registerName: String, val incValue: Int, val condition: Condition)
data class Condition(val registerName: String, val comparisonOperator: ComparisonOperator, val value: Int)
data class Results(val registers: Map<String, Int>, val highestSeenValue: Int)

fun runInstructions(input: String): Results {
    return runInstructions(parseInput(input))
}

fun runInstructions(instructions: List<Instruction>): Results {
    var highestSeenValue: Int = Int.MIN_VALUE
    val registers = mutableMapOf<String, Int>()
    for (instruction in instructions) {
        val cond = instruction.condition
        registers.putIfAbsent(instruction.registerName, 0)
        registers.putIfAbsent(cond.registerName, 0)
        if (cond.comparisonOperator.apply(registers.getOrDefault(cond.registerName, 0), cond.value)) {
            registers.merge(instruction.registerName, instruction.incValue, fun(orig, incBy): Int {
                //This is mildly disgusting, but gets the answer quickly
                val res = orig + incBy
                if (res > highestSeenValue) {
                    highestSeenValue = res
                }
                return res
            })
        }
    }
    return Results(registers, highestSeenValue)
}

fun parseInput(input: String): List<Instruction> {
    return input.lines()
            .filter(String::isNotBlank)
            .map(::lineToInstruction)

}

fun lineToInstruction(line: String): Instruction {
    val parts: List<String> = line.trim().split("""\s""".toRegex())
    val registerName: String = parts[0]
    val incBy: Int = if (parts[1] == "inc") parts[2].toInt() else parts[2].toInt() * -1
    val conditionRegisterName: String = parts[4]
    val conditionValue: Int = parts[6].toInt()
    val operator: ComparisonOperator = when (parts[5]) {
        "==" -> EqualTo
        "!=" -> NotEqualTo
        ">" -> GreaterThan
        ">=" -> GreaterThanOrEqualTo
        "<" -> LessThan
        "<=" -> LessThanOrEqualTo
        else -> throw IllegalArgumentException()
    }

    return Instruction(registerName, incBy, Condition(conditionRegisterName, operator, conditionValue))
}

fun main(args: Array<String>) {
    val input = MethodHandles.lookup().lookupClass().getResourceAsStream("/Day08Input.txt").bufferedReader().readText()
    val results = runInstructions(input)

    println("Part One Answer: ${results.registers.values.max()}")
    println("Part Two Answer: ${results.highestSeenValue}")
}

Compiled from "Day08.kt"
public final class com.morninghacks.aoc2017.Day08Kt {
  public static final com.morninghacks.aoc2017.Results runInstructions(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #19                 // Method parseInput:(Ljava/lang/String;)Ljava/util/List;
      10: invokestatic  #22                 // Method runInstructions:(Ljava/util/List;)Lcom/morninghacks/aoc2017/Results;
      13: areturn

  public static final com.morninghacks.aoc2017.Results runInstructions(java.util.List<com.morninghacks.aoc2017.Instruction>);
    Code:
       0: aload_0
       1: ldc           #26                 // String instructions
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #28                 // class kotlin/jvm/internal/Ref$IntRef
       9: dup
      10: invokespecial #32                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      13: astore_1
      14: aload_1
      15: ldc           #33                 // int -2147483648
      17: putfield      #37                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      20: new           #39                 // class java/util/LinkedHashMap
      23: dup
      24: invokespecial #40                 // Method java/util/LinkedHashMap."<init>":()V
      27: checkcast     #42                 // class java/util/Map
      30: astore_2
      31: aload_0
      32: invokeinterface #48,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      37: astore_3
      38: aload_3
      39: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          168
      47: aload_3
      48: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: checkcast     #60                 // class com/morninghacks/aoc2017/Instruction
      56: astore        4
      58: aload         4
      60: invokevirtual #64                 // Method com/morninghacks/aoc2017/Instruction.getCondition:()Lcom/morninghacks/aoc2017/Condition;
      63: astore        5
      65: aload_2
      66: aload         4
      68: invokevirtual #68                 // Method com/morninghacks/aoc2017/Instruction.getRegisterName:()Ljava/lang/String;
      71: iconst_0
      72: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      75: invokeinterface #78,  3           // InterfaceMethod java/util/Map.putIfAbsent:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      80: pop
      81: aload_2
      82: aload         5
      84: invokevirtual #81                 // Method com/morninghacks/aoc2017/Condition.getRegisterName:()Ljava/lang/String;
      87: iconst_0
      88: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: invokeinterface #78,  3           // InterfaceMethod java/util/Map.putIfAbsent:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      96: pop
      97: aload         5
      99: invokevirtual #85                 // Method com/morninghacks/aoc2017/Condition.getComparisonOperator:()Lcom/morninghacks/aoc2017/ComparisonOperator;
     102: aload_2
     103: aload         5
     105: invokevirtual #81                 // Method com/morninghacks/aoc2017/Condition.getRegisterName:()Ljava/lang/String;
     108: iconst_0
     109: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: invokeinterface #88,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     117: checkcast     #90                 // class java/lang/Number
     120: invokevirtual #94                 // Method java/lang/Number.intValue:()I
     123: aload         5
     125: invokevirtual #97                 // Method com/morninghacks/aoc2017/Condition.getValue:()I
     128: invokevirtual #103                // Method com/morninghacks/aoc2017/ComparisonOperator.apply:(II)Z
     131: ifeq          38
     134: aload_2
     135: aload         4
     137: invokevirtual #68                 // Method com/morninghacks/aoc2017/Instruction.getRegisterName:()Ljava/lang/String;
     140: aload         4
     142: invokevirtual #106                // Method com/morninghacks/aoc2017/Instruction.getIncValue:()I
     145: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     148: aload_1
     149: invokedynamic #125,  0            // InvokeDynamic #0:invoke:(Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function2;
     154: invokedynamic #135,  0            // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     159: invokeinterface #139,  4          // InterfaceMethod java/util/Map.merge:(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     164: pop
     165: goto          38
     168: new           #141                // class com/morninghacks/aoc2017/Results
     171: dup
     172: aload_2
     173: aload_1
     174: getfield      #37                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     177: invokespecial #144                // Method com/morninghacks/aoc2017/Results."<init>":(Ljava/util/Map;I)V
     180: areturn

  public static final java.util.List<com.morninghacks.aoc2017.Instruction> parseInput(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #156                // class java/lang/CharSequence
      10: invokestatic  #162                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      13: checkcast     #164                // class java/lang/Iterable
      16: astore_1
      17: nop
      18: iconst_0
      19: istore_2
      20: aload_1
      21: astore_3
      22: new           #166                // class java/util/ArrayList
      25: dup
      26: invokespecial #167                // Method java/util/ArrayList."<init>":()V
      29: checkcast     #169                // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #170,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          107
      55: aload         6
      57: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         7
      66: checkcast     #172                // class java/lang/String
      69: astore        8
      71: iconst_0
      72: istore        9
      74: aload         8
      76: checkcast     #156                // class java/lang/CharSequence
      79: invokestatic  #176                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      82: ifne          89
      85: iconst_1
      86: goto          90
      89: iconst_0
      90: nop
      91: ifeq          45
      94: aload         4
      96: aload         7
      98: invokeinterface #180,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     103: pop
     104: goto          45
     107: aload         4
     109: checkcast     #44                 // class java/util/List
     112: nop
     113: checkcast     #164                // class java/lang/Iterable
     116: astore_1
     117: nop
     118: iconst_0
     119: istore_2
     120: aload_1
     121: astore_3
     122: new           #166                // class java/util/ArrayList
     125: dup
     126: aload_1
     127: bipush        10
     129: invokestatic  #186                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     132: invokespecial #189                // Method java/util/ArrayList."<init>":(I)V
     135: checkcast     #169                // class java/util/Collection
     138: astore        4
     140: iconst_0
     141: istore        5
     143: aload_3
     144: invokeinterface #170,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     149: astore        6
     151: aload         6
     153: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     158: ifeq          201
     161: aload         6
     163: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     168: astore        7
     170: aload         4
     172: aload         7
     174: checkcast     #172                // class java/lang/String
     177: astore        8
     179: astore        10
     181: iconst_0
     182: istore        9
     184: aload         8
     186: invokestatic  #193                // Method lineToInstruction:(Ljava/lang/String;)Lcom/morninghacks/aoc2017/Instruction;
     189: aload         10
     191: swap
     192: invokeinterface #180,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          151
     201: aload         4
     203: checkcast     #44                 // class java/util/List
     206: nop
     207: areturn

  public static final com.morninghacks.aoc2017.Instruction lineToInstruction(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #212                // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #156                // class java/lang/CharSequence
      10: invokestatic  #216                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      13: invokevirtual #219                // Method java/lang/Object.toString:()Ljava/lang/String;
      16: checkcast     #156                // class java/lang/CharSequence
      19: astore_2
      20: new           #221                // class kotlin/text/Regex
      23: dup
      24: ldc           #223                // String \\s
      26: invokespecial #226                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      29: astore_3
      30: iconst_0
      31: istore        4
      33: aload_3
      34: aload_2
      35: iload         4
      37: invokevirtual #230                // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      40: astore_1
      41: aload_1
      42: iconst_0
      43: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      48: checkcast     #172                // class java/lang/String
      51: astore_2
      52: aload_1
      53: iconst_1
      54: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: ldc           #236                // String inc
      61: invokestatic  #240                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      64: ifeq          83
      67: aload_1
      68: iconst_2
      69: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      74: checkcast     #172                // class java/lang/String
      77: invokestatic  #244                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      80: goto          98
      83: aload_1
      84: iconst_2
      85: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      90: checkcast     #172                // class java/lang/String
      93: invokestatic  #244                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      96: iconst_m1
      97: imul
      98: istore_3
      99: aload_1
     100: iconst_4
     101: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     106: checkcast     #172                // class java/lang/String
     109: astore        4
     111: aload_1
     112: bipush        6
     114: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     119: checkcast     #172                // class java/lang/String
     122: invokestatic  #244                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     125: istore        5
     127: aload_1
     128: iconst_5
     129: invokeinterface #234,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #172                // class java/lang/String
     137: astore        7
     139: aload         7
     141: invokevirtual #247                // Method java/lang/String.hashCode:()I
     144: lookupswitch  { // 6
                    60: 244
                    62: 258
                  1084: 230
                  1921: 217
                  1952: 204
                  1983: 272
               default: 340
          }
     204: aload         7
     206: ldc           #249                // String ==
     208: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     211: ifne          286
     214: goto          340
     217: aload         7
     219: ldc           #254                // String <=
     221: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     224: ifne          331
     227: goto          340
     230: aload         7
     232: ldc_w         #256                // String !=
     235: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     238: ifne          295
     241: goto          340
     244: aload         7
     246: ldc_w         #258                // String <
     249: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     252: ifne          322
     255: goto          340
     258: aload         7
     260: ldc_w         #260                // String >
     263: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     266: ifne          304
     269: goto          340
     272: aload         7
     274: ldc_w         #262                // String >=
     277: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     280: ifne          313
     283: goto          340
     286: getstatic     #268                // Field com/morninghacks/aoc2017/EqualTo.INSTANCE:Lcom/morninghacks/aoc2017/EqualTo;
     289: checkcast     #99                 // class com/morninghacks/aoc2017/ComparisonOperator
     292: goto          348
     295: getstatic     #273                // Field com/morninghacks/aoc2017/NotEqualTo.INSTANCE:Lcom/morninghacks/aoc2017/NotEqualTo;
     298: checkcast     #99                 // class com/morninghacks/aoc2017/ComparisonOperator
     301: goto          348
     304: getstatic     #278                // Field com/morninghacks/aoc2017/GreaterThan.INSTANCE:Lcom/morninghacks/aoc2017/GreaterThan;
     307: checkcast     #99                 // class com/morninghacks/aoc2017/ComparisonOperator
     310: goto          348
     313: getstatic     #283                // Field com/morninghacks/aoc2017/GreaterThanOrEqualTo.INSTANCE:Lcom/morninghacks/aoc2017/GreaterThanOrEqualTo;
     316: checkcast     #99                 // class com/morninghacks/aoc2017/ComparisonOperator
     319: goto          348
     322: getstatic     #288                // Field com/morninghacks/aoc2017/LessThan.INSTANCE:Lcom/morninghacks/aoc2017/LessThan;
     325: checkcast     #99                 // class com/morninghacks/aoc2017/ComparisonOperator
     328: goto          348
     331: getstatic     #293                // Field com/morninghacks/aoc2017/LessThanOrEqualTo.INSTANCE:Lcom/morninghacks/aoc2017/LessThanOrEqualTo;
     334: checkcast     #99                 // class com/morninghacks/aoc2017/ComparisonOperator
     337: goto          348
     340: new           #295                // class java/lang/IllegalArgumentException
     343: dup
     344: invokespecial #296                // Method java/lang/IllegalArgumentException."<init>":()V
     347: athrow
     348: astore        6
     350: new           #60                 // class com/morninghacks/aoc2017/Instruction
     353: dup
     354: aload_2
     355: iload_3
     356: new           #80                 // class com/morninghacks/aoc2017/Condition
     359: dup
     360: aload         4
     362: aload         6
     364: iload         5
     366: invokespecial #299                // Method com/morninghacks/aoc2017/Condition."<init>":(Ljava/lang/String;Lcom/morninghacks/aoc2017/ComparisonOperator;I)V
     369: invokespecial #302                // Method com/morninghacks/aoc2017/Instruction."<init>":(Ljava/lang/String;ILcom/morninghacks/aoc2017/Condition;)V
     372: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc_w         #313                // String args
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: invokestatic  #319                // Method java/lang/invoke/MethodHandles.lookup:()Ljava/lang/invoke/MethodHandles$Lookup;
      10: invokevirtual #325                // Method java/lang/invoke/MethodHandles$Lookup.lookupClass:()Ljava/lang/Class;
      13: ldc_w         #327                // String /Day08Input.txt
      16: invokevirtual #333                // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      19: dup
      20: ldc_w         #335                // String getResourceAsStream(...)
      23: invokestatic  #338                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      26: astore_2
      27: getstatic     #344                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      30: astore_3
      31: new           #346                // class java/io/InputStreamReader
      34: dup
      35: aload_2
      36: aload_3
      37: invokespecial #349                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      40: checkcast     #351                // class java/io/Reader
      43: astore        4
      45: sipush        8192
      48: istore        5
      50: aload         4
      52: instanceof    #353                // class java/io/BufferedReader
      55: ifeq          66
      58: aload         4
      60: checkcast     #353                // class java/io/BufferedReader
      63: goto          77
      66: new           #353                // class java/io/BufferedReader
      69: dup
      70: aload         4
      72: iload         5
      74: invokespecial #356                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      77: checkcast     #351                // class java/io/Reader
      80: invokestatic  #362                // Method kotlin/io/TextStreamsKt.readText:(Ljava/io/Reader;)Ljava/lang/String;
      83: astore_1
      84: aload_1
      85: invokestatic  #364                // Method runInstructions:(Ljava/lang/String;)Lcom/morninghacks/aoc2017/Results;
      88: astore_2
      89: new           #366                // class java/lang/StringBuilder
      92: dup
      93: invokespecial #367                // Method java/lang/StringBuilder."<init>":()V
      96: ldc_w         #369                // String Part One Answer:
      99: invokevirtual #373                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     102: aload_2
     103: invokevirtual #377                // Method com/morninghacks/aoc2017/Results.getRegisters:()Ljava/util/Map;
     106: invokeinterface #381,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     111: checkcast     #164                // class java/lang/Iterable
     114: invokestatic  #385                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     117: checkcast     #90                 // class java/lang/Number
     120: invokevirtual #94                 // Method java/lang/Number.intValue:()I
     123: invokevirtual #388                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     126: invokevirtual #389                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     129: getstatic     #395                // Field java/lang/System.out:Ljava/io/PrintStream;
     132: swap
     133: invokevirtual #401                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     136: new           #366                // class java/lang/StringBuilder
     139: dup
     140: invokespecial #367                // Method java/lang/StringBuilder."<init>":()V
     143: ldc_w         #403                // String Part Two Answer:
     146: invokevirtual #373                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     149: aload_2
     150: invokevirtual #406                // Method com/morninghacks/aoc2017/Results.getHighestSeenValue:()I
     153: invokevirtual #388                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     156: invokevirtual #389                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     159: getstatic     #395                // Field java/lang/System.out:Ljava/io/PrintStream;
     162: swap
     163: invokevirtual #401                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     166: return

  private static final int runInstructions$lambda$0(kotlin.jvm.internal.Ref$IntRef, java.lang.Integer, java.lang.Integer);
    Code:
       0: aload_1
       1: invokevirtual #415                // Method java/lang/Integer.intValue:()I
       4: aload_2
       5: invokestatic  #418                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       8: aload_2
       9: invokevirtual #415                // Method java/lang/Integer.intValue:()I
      12: iadd
      13: istore_3
      14: iload_3
      15: aload_0
      16: getfield      #37                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      19: if_icmple     27
      22: aload_0
      23: iload_3
      24: putfield      #37                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      27: iload_3
      28: ireturn

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


package codeforces.problem1B

fun convertToExcelFormat(coord: String, alphabet: CharArray): String {
    val row = coord.substring(1, coord.indexOf('C'))
    var column = coord.substring(coord.indexOf('C') + 1).toInt()

    // Convert column number to letters
    val resultingColumn = StringBuilder()

    while (column > 26) {
        var remainder = column % 26
        if (remainder == 0) { // 0 is represented by Z with one less letter
            remainder = 26
        }
        resultingColumn.append(alphabet[remainder])
        column -= remainder
        column /= 26
    }
    resultingColumn.append(alphabet[column])
    return "${resultingColumn.reverse()}$row"
}

fun convertToNumericalFormat(coord: String, alphabet: CharArray): String {
    val firstDigitPos = coord.indexOfFirst { it.isDigit() }
    val row = coord.substring(firstDigitPos)
    val column = coord.substring(0, firstDigitPos)

    var convertedColumn = 0

    var powerOf26 = 1
    for (i in column.length - 1 downTo 0) {
        convertedColumn += powerOf26 * alphabet.binarySearch(column[i])
        powerOf26 *= 26
    }

    return "R${row}C$convertedColumn"
}

fun main() {
    val numLines = readLine()!!.toInt()
    val alphabet = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()

    val outputs = mutableListOf<String>()
    for (i in 0 until numLines) {
        val currentLine = readLine()!!

        val positionOfC = currentLine.indexOf('C')
        if (positionOfC > 0 && currentLine[positionOfC - 1].isDigit()) {
            // Input is in Row Column format
            outputs.add(convertToExcelFormat(currentLine, alphabet))
        } else {
            // Input is in Letter Row format
            outputs.add(convertToNumericalFormat(currentLine, alphabet))
        }
    }

    println(outputs.joinToString("\n"))
}

Compiled from "Main.kt"
public final class codeforces.problem1B.MainKt {
  public static final java.lang.String convertToExcelFormat(java.lang.String, char[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String coord
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String alphabet
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_1
      14: aload_0
      15: checkcast     #19                 // class java/lang/CharSequence
      18: bipush        67
      20: iconst_0
      21: iconst_0
      22: bipush        6
      24: aconst_null
      25: invokestatic  #25                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      28: invokevirtual #31                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      31: dup
      32: ldc           #33                 // String substring(...)
      34: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      37: astore_2
      38: nop
      39: aload_0
      40: aload_0
      41: checkcast     #19                 // class java/lang/CharSequence
      44: bipush        67
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #25                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      54: iconst_1
      55: iadd
      56: invokevirtual #39                 // Method java/lang/String.substring:(I)Ljava/lang/String;
      59: dup
      60: ldc           #33                 // String substring(...)
      62: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      65: invokestatic  #45                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      68: istore_3
      69: new           #47                 // class java/lang/StringBuilder
      72: dup
      73: invokespecial #51                 // Method java/lang/StringBuilder."<init>":()V
      76: astore        4
      78: iload_3
      79: bipush        26
      81: if_icmple     122
      84: iload_3
      85: bipush        26
      87: irem
      88: istore        5
      90: iload         5
      92: ifne          99
      95: bipush        26
      97: istore        5
      99: aload         4
     101: aload_1
     102: iload         5
     104: caload
     105: invokevirtual #55                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     108: pop
     109: iload_3
     110: iload         5
     112: isub
     113: istore_3
     114: iload_3
     115: bipush        26
     117: idiv
     118: istore_3
     119: goto          78
     122: aload         4
     124: aload_1
     125: iload_3
     126: caload
     127: invokevirtual #55                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     130: pop
     131: new           #47                 // class java/lang/StringBuilder
     134: dup
     135: invokespecial #51                 // Method java/lang/StringBuilder."<init>":()V
     138: aload         4
     140: invokevirtual #59                 // Method java/lang/StringBuilder.reverse:()Ljava/lang/StringBuilder;
     143: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     146: aload_2
     147: invokevirtual #65                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     150: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     153: areturn

  public static final java.lang.String convertToNumericalFormat(java.lang.String, char[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String coord
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String alphabet
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #19                 // class java/lang/CharSequence
      16: astore_3
      17: iconst_0
      18: istore        4
      20: iconst_0
      21: istore        5
      23: aload_3
      24: invokeinterface #82,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      29: istore        6
      31: iload         5
      33: iload         6
      35: if_icmpge     71
      38: aload_3
      39: iload         5
      41: invokeinterface #86,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      46: istore        7
      48: iconst_0
      49: istore        8
      51: iload         7
      53: invokestatic  #92                 // Method java/lang/Character.isDigit:(C)Z
      56: nop
      57: ifeq          65
      60: iload         5
      62: goto          72
      65: iinc          5, 1
      68: goto          31
      71: iconst_m1
      72: istore_2
      73: aload_0
      74: iload_2
      75: invokevirtual #39                 // Method java/lang/String.substring:(I)Ljava/lang/String;
      78: dup
      79: ldc           #33                 // String substring(...)
      81: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      84: astore_3
      85: aload_0
      86: iconst_0
      87: iload_2
      88: invokevirtual #31                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      91: dup
      92: ldc           #33                 // String substring(...)
      94: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      97: astore        4
      99: iconst_0
     100: istore        5
     102: iconst_1
     103: istore        6
     105: aload         4
     107: invokevirtual #93                 // Method java/lang/String.length:()I
     110: iconst_1
     111: isub
     112: istore        7
     114: iconst_m1
     115: iload         7
     117: if_icmpge     157
     120: iload         5
     122: iload         6
     124: aload_1
     125: aload         4
     127: iload         7
     129: invokevirtual #94                 // Method java/lang/String.charAt:(I)C
     132: iconst_0
     133: iconst_0
     134: bipush        6
     136: aconst_null
     137: invokestatic  #100                // Method kotlin/collections/ArraysKt.binarySearch$default:([CCIIILjava/lang/Object;)I
     140: imul
     141: iadd
     142: istore        5
     144: iload         6
     146: bipush        26
     148: imul
     149: istore        6
     151: iinc          7, -1
     154: goto          114
     157: new           #47                 // class java/lang/StringBuilder
     160: dup
     161: invokespecial #51                 // Method java/lang/StringBuilder."<init>":()V
     164: bipush        82
     166: invokevirtual #55                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     169: aload_3
     170: invokevirtual #65                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     173: bipush        67
     175: invokevirtual #55                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     178: iload         5
     180: invokevirtual #103                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     183: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     186: areturn

  public static final void main();
    Code:
       0: invokestatic  #121                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: invokestatic  #45                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      10: istore_0
      11: ldc           #127                // String #ABCDEFGHIJKLMNOPQRSTUVWXYZ
      13: invokevirtual #131                // Method java/lang/String.toCharArray:()[C
      16: dup
      17: ldc           #133                // String toCharArray(...)
      19: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      22: astore_1
      23: new           #135                // class java/util/ArrayList
      26: dup
      27: invokespecial #136                // Method java/util/ArrayList."<init>":()V
      30: checkcast     #138                // class java/util/List
      33: astore_2
      34: iconst_0
      35: istore_3
      36: iload_3
      37: iload_0
      38: if_icmpge     121
      41: invokestatic  #121                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      44: dup
      45: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      48: astore        4
      50: aload         4
      52: checkcast     #19                 // class java/lang/CharSequence
      55: bipush        67
      57: iconst_0
      58: iconst_0
      59: bipush        6
      61: aconst_null
      62: invokestatic  #25                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      65: istore        5
      67: iload         5
      69: ifle          102
      72: aload         4
      74: iload         5
      76: iconst_1
      77: isub
      78: invokevirtual #94                 // Method java/lang/String.charAt:(I)C
      81: invokestatic  #92                 // Method java/lang/Character.isDigit:(C)Z
      84: ifeq          102
      87: aload_2
      88: aload         4
      90: aload_1
      91: invokestatic  #140                // Method convertToExcelFormat:(Ljava/lang/String;[C)Ljava/lang/String;
      94: invokeinterface #144,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      99: goto          114
     102: aload_2
     103: aload         4
     105: aload_1
     106: invokestatic  #146                // Method convertToNumericalFormat:(Ljava/lang/String;[C)Ljava/lang/String;
     109: invokeinterface #144,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     114: pop
     115: iinc          3, 1
     118: goto          36
     121: aload_2
     122: checkcast     #148                // class java/lang/Iterable
     125: ldc           #150                // String \n
     127: checkcast     #19                 // class java/lang/CharSequence
     130: aconst_null
     131: aconst_null
     132: iconst_0
     133: aconst_null
     134: aconst_null
     135: bipush        62
     137: aconst_null
     138: invokestatic  #156                // 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;
     141: getstatic     #162                // Field java/lang/System.out:Ljava/io/PrintStream;
     144: swap
     145: invokevirtual #167                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     148: return

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


package com.ubertob.fotf.bowlingkata

enum class Pins(val number: Int) {
    zero(0),
    one(1),
    two(2),
    three(3),
    four(4),
    five(5),
    six(6),
    seven(7),
    eight(8),
    nine(9),
    ten(10)
}

data class BowlingGameFP(val rolls: List<Pins>, val scoreFn: (List<Pins>) -> Int) {

    val score by lazy { scoreFn(rolls) }

    fun roll(pins: Pins): BowlingGameFP =
        copy(rolls = rolls + pins)

    companion object {
        fun newBowlingGame() = BowlingGameFP(emptyList(), Companion::calcBowlingScoreRec)

        fun calcBowlingScore(rolls: List<Pins>): Int {
            fun getRoll(roll: Int): Int = rolls.getOrElse(roll) { Pins.zero }.number
            fun isStrike(frameIndex: Int): Boolean = getRoll(frameIndex) == 10
            fun sumOfBallsInFrame(frameIndex: Int): Int = getRoll(frameIndex) + getRoll(frameIndex + 1)
            fun spareBonus(frameIndex: Int): Int = getRoll(frameIndex + 2)
            fun strikeBonus(frameIndex: Int): Int = getRoll(frameIndex + 1) + getRoll(frameIndex + 2)
            fun isSpare(frameIndex: Int): Boolean = getRoll(frameIndex) + getRoll(frameIndex + 1) == 10

            var score = 0
            var frameIndex = 0
            for (frame in 0..9) {
                if (isStrike(frameIndex)) {
                    score += 10 + strikeBonus(frameIndex)
                    frameIndex++
                } else if (isSpare(frameIndex)) {
                    score += 10 + spareBonus(frameIndex)
                    frameIndex += 2
                } else {
                    score += sumOfBallsInFrame(frameIndex)
                    frameIndex += 2
                }
            }
            return score
        }

        fun calcBowlingScoreRec(rolls: List<Pins>): Int {
            val lastFrame = 10
            val noOfPins = 10
            fun List<Int>.isStrike(): Boolean = first() == noOfPins
            fun List<Int>.isSpare(): Boolean = take(2).sum() == noOfPins

            fun calcFrameScore(frame: Int, rolls: List<Int>): Int =
                when {
                    frame == lastFrame || rolls.size < 3 ->
                        rolls.sum()

                    rolls.isStrike() ->
                        rolls.take(3).sum() + calcFrameScore(frame + 1, rolls.drop(1))

                    rolls.isSpare() ->
                        rolls.take(3).sum() + calcFrameScore(frame + 1, rolls.drop(2))

                    else ->
                        rolls.take(2).sum() + calcFrameScore(frame + 1, rolls.drop(2))
                }
            return calcFrameScore(1, rolls.map(Pins::number))
        }
    }
}

fun scoreAndLog(
    fnLog: (Int) -> Unit,
    fnScore: (List<Int>) -> Int
): (List<Int>) -> Int = { rolls ->
    fnScore(rolls).also(fnLog)
}

Compiled from "BowlingGameFP.kt"
public final class com.ubertob.fotf.bowlingkata.BowlingGameFPKt {
  public static final kotlin.jvm.functions.Function1<java.util.List<java.lang.Integer>, java.lang.Integer> scoreAndLog(kotlin.jvm.functions.Function1<? super java.lang.Integer, kotlin.Unit>, kotlin.jvm.functions.Function1<? super java.util.List<java.lang.Integer>, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #10                 // String fnLog
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String fnScore
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: aload_0
      14: invokedynamic #37,  0             // InvokeDynamic #0:invoke:(Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
      19: areturn

  private static final int scoreAndLog$lambda$0(kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1, java.util.List);
    Code:
       0: aload_2
       1: ldc           #40                 // String rolls
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_2
       8: invokeinterface #44,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      13: astore_3
      14: aload_1
      15: aload_3
      16: invokeinterface #44,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      21: pop
      22: aload_3
      23: checkcast     #46                 // class java/lang/Number
      26: invokevirtual #50                 // Method java/lang/Number.intValue:()I
      29: ireturn
}

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

  public final com.ubertob.fotf.bowlingkata.BowlingGameFP newBowlingGame();
    Code:
       0: new           #15                 // class com/ubertob/fotf/bowlingkata/BowlingGameFP
       3: dup
       4: invokestatic  #21                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
       7: new           #23                 // class com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion$newBowlingGame$1
      10: dup
      11: getstatic     #26                 // Field com/ubertob/fotf/bowlingkata/BowlingGameFP.Companion:Lcom/ubertob/fotf/bowlingkata/BowlingGameFP$Companion;
      14: invokespecial #29                 // Method com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion$newBowlingGame$1."<init>":(Ljava/lang/Object;)V
      17: checkcast     #31                 // class kotlin/jvm/functions/Function1
      20: invokespecial #34                 // Method com/ubertob/fotf/bowlingkata/BowlingGameFP."<init>":(Ljava/util/List;Lkotlin/jvm/functions/Function1;)V
      23: areturn

  public final int calcBowlingScore(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>);
    Code:
       0: aload_1
       1: ldc           #39                 // String rolls
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: iload         4
      15: bipush        10
      17: if_icmpge     87
      20: aload_1
      21: iload_3
      22: invokestatic  #49                 // Method calcBowlingScore$isStrike:(Ljava/util/List;I)Z
      25: ifeq          45
      28: iload_2
      29: bipush        10
      31: aload_1
      32: iload_3
      33: invokestatic  #53                 // Method calcBowlingScore$strikeBonus:(Ljava/util/List;I)I
      36: iadd
      37: iadd
      38: istore_2
      39: iinc          3, 1
      42: goto          81
      45: aload_1
      46: iload_3
      47: invokestatic  #56                 // Method calcBowlingScore$isSpare:(Ljava/util/List;I)Z
      50: ifeq          70
      53: iload_2
      54: bipush        10
      56: aload_1
      57: iload_3
      58: invokestatic  #59                 // Method calcBowlingScore$spareBonus:(Ljava/util/List;I)I
      61: iadd
      62: iadd
      63: istore_2
      64: iinc          3, 2
      67: goto          81
      70: iload_2
      71: aload_1
      72: iload_3
      73: invokestatic  #62                 // Method calcBowlingScore$sumOfBallsInFrame:(Ljava/util/List;I)I
      76: iadd
      77: istore_2
      78: iinc          3, 2
      81: iinc          4, 1
      84: goto          13
      87: iload_2
      88: ireturn

  public final int calcBowlingScoreRec(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>);
    Code:
       0: aload_1
       1: ldc           #39                 // String rolls
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        10
       8: istore_2
       9: bipush        10
      11: istore_3
      12: iload_2
      13: iload_3
      14: iconst_1
      15: aload_1
      16: checkcast     #70                 // class java/lang/Iterable
      19: astore        4
      21: istore        15
      23: istore        14
      25: istore        13
      27: iconst_0
      28: istore        5
      30: aload         4
      32: astore        6
      34: new           #72                 // class java/util/ArrayList
      37: dup
      38: aload         4
      40: bipush        10
      42: invokestatic  #76                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      45: invokespecial #79                 // Method java/util/ArrayList."<init>":(I)V
      48: checkcast     #81                 // class java/util/Collection
      51: astore        7
      53: iconst_0
      54: istore        8
      56: aload         6
      58: invokeinterface #85,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        9
      65: aload         9
      67: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          118
      75: aload         9
      77: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        10
      84: aload         7
      86: aload         10
      88: checkcast     #97                 // class com/ubertob/fotf/bowlingkata/Pins
      91: astore        11
      93: astore        16
      95: iconst_0
      96: istore        12
      98: aload         11
     100: invokevirtual #101                // Method com/ubertob/fotf/bowlingkata/Pins.getNumber:()I
     103: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aload         16
     108: swap
     109: invokeinterface #111,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          65
     118: aload         7
     120: checkcast     #113                // class java/util/List
     123: nop
     124: astore        16
     126: iload         13
     128: iload         14
     130: iload         15
     132: aload         16
     134: invokestatic  #117                // Method calcBowlingScoreRec$calcFrameScore:(IIILjava/util/List;)I
     137: ireturn

  private static final int calcBowlingScore$getRoll(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, int);
    Code:
       0: aload_0
       1: astore_2
       2: iconst_0
       3: iload_1
       4: if_icmpgt     25
       7: iload_1
       8: aload_2
       9: invokeinterface #136,  1          // InterfaceMethod java/util/List.size:()I
      14: if_icmpge     21
      17: iconst_1
      18: goto          26
      21: iconst_0
      22: goto          26
      25: iconst_0
      26: ifeq          39
      29: aload_2
      30: iload_1
      31: invokeinterface #140,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      36: goto          47
      39: iload_1
      40: istore_3
      41: iconst_0
      42: istore        4
      44: getstatic     #143                // Field com/ubertob/fotf/bowlingkata/Pins.zero:Lcom/ubertob/fotf/bowlingkata/Pins;
      47: checkcast     #97                 // class com/ubertob/fotf/bowlingkata/Pins
      50: invokevirtual #101                // Method com/ubertob/fotf/bowlingkata/Pins.getNumber:()I
      53: ireturn

  private static final boolean calcBowlingScore$isStrike(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
       5: bipush        10
       7: if_icmpne     14
      10: iconst_1
      11: goto          15
      14: iconst_0
      15: ireturn

  private static final int calcBowlingScore$sumOfBallsInFrame(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
       5: aload_0
       6: iload_1
       7: iconst_1
       8: iadd
       9: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
      12: iadd
      13: ireturn

  private static final int calcBowlingScore$spareBonus(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, int);
    Code:
       0: aload_0
       1: iload_1
       2: iconst_2
       3: iadd
       4: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
       7: ireturn

  private static final int calcBowlingScore$strikeBonus(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, int);
    Code:
       0: aload_0
       1: iload_1
       2: iconst_1
       3: iadd
       4: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
       7: aload_0
       8: iload_1
       9: iconst_2
      10: iadd
      11: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
      14: iadd
      15: ireturn

  private static final boolean calcBowlingScore$isSpare(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
       5: aload_0
       6: iload_1
       7: iconst_1
       8: iadd
       9: invokestatic  #150                // Method calcBowlingScore$getRoll:(Ljava/util/List;I)I
      12: iadd
      13: bipush        10
      15: if_icmpne     22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ireturn

  private static final boolean calcBowlingScoreRec$isStrike$1(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: invokestatic  #156                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
       4: checkcast     #158                // class java/lang/Number
       7: invokevirtual #161                // Method java/lang/Number.intValue:()I
      10: iload_1
      11: if_icmpne     18
      14: iconst_1
      15: goto          19
      18: iconst_0
      19: ireturn

  private static final boolean calcBowlingScoreRec$isSpare$2(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: checkcast     #70                 // class java/lang/Iterable
       4: iconst_2
       5: invokestatic  #167                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
       8: checkcast     #70                 // class java/lang/Iterable
      11: invokestatic  #171                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      14: iload_1
      15: if_icmpne     22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ireturn

  private static final int calcBowlingScoreRec$calcFrameScore(int, int, int, java.util.List<java.lang.Integer>);
    Code:
       0: nop
       1: iload_2
       2: iload_0
       3: if_icmpeq     16
       6: aload_3
       7: invokeinterface #136,  1          // InterfaceMethod java/util/List.size:()I
      12: iconst_3
      13: if_icmpge     26
      16: aload_3
      17: checkcast     #70                 // class java/lang/Iterable
      20: invokestatic  #171                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      23: goto          141
      26: aload_3
      27: iload_1
      28: invokestatic  #175                // Method calcBowlingScoreRec$isStrike$1:(Ljava/util/List;I)Z
      31: ifeq          68
      34: aload_3
      35: checkcast     #70                 // class java/lang/Iterable
      38: iconst_3
      39: invokestatic  #167                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      42: checkcast     #70                 // class java/lang/Iterable
      45: invokestatic  #171                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      48: iload_0
      49: iload_1
      50: iload_2
      51: iconst_1
      52: iadd
      53: aload_3
      54: checkcast     #70                 // class java/lang/Iterable
      57: iconst_1
      58: invokestatic  #178                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      61: invokestatic  #117                // Method calcBowlingScoreRec$calcFrameScore:(IIILjava/util/List;)I
      64: iadd
      65: goto          141
      68: aload_3
      69: iload_1
      70: invokestatic  #180                // Method calcBowlingScoreRec$isSpare$2:(Ljava/util/List;I)Z
      73: ifeq          110
      76: aload_3
      77: checkcast     #70                 // class java/lang/Iterable
      80: iconst_3
      81: invokestatic  #167                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      84: checkcast     #70                 // class java/lang/Iterable
      87: invokestatic  #171                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      90: iload_0
      91: iload_1
      92: iload_2
      93: iconst_1
      94: iadd
      95: aload_3
      96: checkcast     #70                 // class java/lang/Iterable
      99: iconst_2
     100: invokestatic  #178                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     103: invokestatic  #117                // Method calcBowlingScoreRec$calcFrameScore:(IIILjava/util/List;)I
     106: iadd
     107: goto          141
     110: aload_3
     111: checkcast     #70                 // class java/lang/Iterable
     114: iconst_2
     115: invokestatic  #167                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     118: checkcast     #70                 // class java/lang/Iterable
     121: invokestatic  #171                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     124: iload_0
     125: iload_1
     126: iload_2
     127: iconst_1
     128: iadd
     129: aload_3
     130: checkcast     #70                 // class java/lang/Iterable
     133: iconst_2
     134: invokestatic  #178                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     137: invokestatic  #117                // Method calcBowlingScoreRec$calcFrameScore:(IIILjava/util/List;)I
     140: iadd
     141: ireturn

  public com.ubertob.fotf.bowlingkata.BowlingGameFP$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #182                // Method "<init>":()V
       4: return
}

Compiled from "BowlingGameFP.kt"
final class com.ubertob.fotf.bowlingkata.BowlingGameFP$Companion$newBowlingGame$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, java.lang.Integer> {
  com.ubertob.fotf.bowlingkata.BowlingGameFP$Companion$newBowlingGame$1(java.lang.Object);
    Code:
       0: aload_0
       1: iconst_1
       2: aload_1
       3: ldc           #11                 // class com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion
       5: ldc           #13                 // String calcBowlingScoreRec
       7: ldc           #15                 // String calcBowlingScoreRec(Ljava/util/List;)I
       9: iconst_0
      10: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Integer invoke(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>);
    Code:
       0: aload_1
       1: ldc           #27                 // String p0
       3: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #35                 // Field receiver:Ljava/lang/Object;
      10: checkcast     #11                 // class com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion
      13: aload_1
      14: invokevirtual #38                 // Method com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion.calcBowlingScoreRec:(Ljava/util/List;)I
      17: invokestatic  #44                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #48                 // class java/util/List
       5: invokevirtual #50                 // Method invoke:(Ljava/util/List;)Ljava/lang/Integer;
       8: areturn
}

Compiled from "BowlingGameFP.kt"
public final class com.ubertob.fotf.bowlingkata.BowlingGameFP {
  public static final com.ubertob.fotf.bowlingkata.BowlingGameFP$Companion Companion;

  private final java.util.List<com.ubertob.fotf.bowlingkata.Pins> rolls;

  private final kotlin.jvm.functions.Function1<java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, java.lang.Integer> scoreFn;

  private final kotlin.Lazy score$delegate;

  public com.ubertob.fotf.bowlingkata.BowlingGameFP(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, kotlin.jvm.functions.Function1<? super java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #10                 // String rolls
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String scoreFn
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field rolls:Ljava/util/List;
      21: aload_0
      22: aload_2
      23: putfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
      26: aload_0
      27: aload_0
      28: invokedynamic #47,  0             // InvokeDynamic #0:invoke:(Lcom/ubertob/fotf/bowlingkata/BowlingGameFP;)Lkotlin/jvm/functions/Function0;
      33: invokestatic  #53                 // Method kotlin/LazyKt.lazy:(Lkotlin/jvm/functions/Function0;)Lkotlin/Lazy;
      36: putfield      #57                 // Field score$delegate:Lkotlin/Lazy;
      39: return

  public final java.util.List<com.ubertob.fotf.bowlingkata.Pins> getRolls();
    Code:
       0: aload_0
       1: getfield      #24                 // Field rolls:Ljava/util/List;
       4: areturn

  public final kotlin.jvm.functions.Function1<java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, java.lang.Integer> getScoreFn();
    Code:
       0: aload_0
       1: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final int getScore();
    Code:
       0: aload_0
       1: getfield      #57                 // Field score$delegate:Lkotlin/Lazy;
       4: astore_1
       5: aload_1
       6: invokeinterface #72,  1           // InterfaceMethod kotlin/Lazy.getValue:()Ljava/lang/Object;
      11: checkcast     #74                 // class java/lang/Number
      14: invokevirtual #77                 // Method java/lang/Number.intValue:()I
      17: ireturn

  public final com.ubertob.fotf.bowlingkata.BowlingGameFP roll(com.ubertob.fotf.bowlingkata.Pins);
    Code:
       0: aload_1
       1: ldc           #81                 // String pins
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_0
       8: getfield      #24                 // Field rolls:Ljava/util/List;
      11: checkcast     #83                 // class java/util/Collection
      14: aload_1
      15: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
      18: aconst_null
      19: iconst_2
      20: aconst_null
      21: invokestatic  #93                 // Method copy$default:(Lcom/ubertob/fotf/bowlingkata/BowlingGameFP;Ljava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/ubertob/fotf/bowlingkata/BowlingGameFP;
      24: areturn

  public final java.util.List<com.ubertob.fotf.bowlingkata.Pins> component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field rolls:Ljava/util/List;
       4: areturn

  public final kotlin.jvm.functions.Function1<java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, java.lang.Integer> component2();
    Code:
       0: aload_0
       1: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
       4: areturn

  public final com.ubertob.fotf.bowlingkata.BowlingGameFP copy(java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, kotlin.jvm.functions.Function1<? super java.util.List<? extends com.ubertob.fotf.bowlingkata.Pins>, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #10                 // String rolls
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String scoreFn
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class com/ubertob/fotf/bowlingkata/BowlingGameFP
      15: dup
      16: aload_1
      17: aload_2
      18: invokespecial #101                // Method "<init>":(Ljava/util/List;Lkotlin/jvm/functions/Function1;)V
      21: areturn

  public static com.ubertob.fotf.bowlingkata.BowlingGameFP copy$default(com.ubertob.fotf.bowlingkata.BowlingGameFP, java.util.List, kotlin.jvm.functions.Function1, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #24                 // Field rolls:Ljava/util/List;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
      21: astore_2
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokevirtual #103                // Method copy:(Ljava/util/List;Lkotlin/jvm/functions/Function1;)Lcom/ubertob/fotf/bowlingkata/BowlingGameFP;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #107                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #108                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #110                // String BowlingGameFP(rolls=
       9: invokevirtual #114                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field rolls:Ljava/util/List;
      16: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #119                // String , scoreFn=
      21: invokevirtual #114                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
      28: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #122                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #124                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field rolls:Ljava/util/List;
       4: invokevirtual #127                // Method java/lang/Object.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
      16: invokevirtual #127                // Method java/lang/Object.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class com/ubertob/fotf/bowlingkata/BowlingGameFP
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class com/ubertob/fotf/bowlingkata/BowlingGameFP
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field rolls:Ljava/util/List;
      25: aload_2
      26: getfield      #24                 // Field rolls:Ljava/util/List;
      29: invokestatic  #136                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
      41: aload_2
      42: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
      45: invokestatic  #136                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: iconst_1
      54: ireturn

  private static final int score_delegate$lambda$0(com.ubertob.fotf.bowlingkata.BowlingGameFP);
    Code:
       0: aload_0
       1: getfield      #27                 // Field scoreFn:Lkotlin/jvm/functions/Function1;
       4: aload_0
       5: getfield      #24                 // Field rolls:Ljava/util/List;
       8: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      13: checkcast     #74                 // class java/lang/Number
      16: invokevirtual #77                 // Method java/lang/Number.intValue:()I
      19: ireturn

  static {};
    Code:
       0: new           #147                // class com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion
       3: dup
       4: aconst_null
       5: invokespecial #150                // Method com/ubertob/fotf/bowlingkata/BowlingGameFP$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #154                // Field Companion:Lcom/ubertob/fotf/bowlingkata/BowlingGameFP$Companion;
      11: return
}


package Day2

import java.io.File

fun main() {
    val lines = File("src", "Day2/input.txt").readLines()
    var totalScore = 0

    lines.forEach {
        val (theirs, mine) = it.split(" ")
        val score = score(map(theirs), map(mine))
        totalScore += score
        println("$theirs $mine: $score")
    }

    println("Total Score: $totalScore")
}

fun score(theirs: String, mine:String): Int {
    var score = 0
    when (mine) {
        "Rock" -> score += 1 // Rock is 1 point
        "Paper" -> score += 2 // Paper is 2 points
        "Scissors" -> score += 3 // Scissors are 3 points
    }

    if (theirs == mine) {
        return score + 3 // Draw is 3 points
    }

    if (
        (theirs == "Rock" && mine == "Paper") || // A Rock is wrapped in a Y Paper
        (theirs == "Paper" && mine == "Scissors") || // B Paper is cut by Z scissors
        (theirs == "Scissors" && mine == "Rock")    // C Scissors is blunted by X Rock
    ) {
        return score + 6; // Win is 6 points
    }

    return score
}

fun map(move: String): String {
    when (move) {
        "A", "X" -> return "Rock"
        "B", "Y" -> return "Paper"
        "C", "Z" -> return "Scissors"
    }

    return ""
}

Compiled from "Day2.kt"
public final class Day2.Day2Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src
       6: ldc           #12                 // String Day2/input.txt
       8: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      11: aconst_null
      12: iconst_1
      13: aconst_null
      14: invokestatic  #22                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      17: astore_0
      18: iconst_0
      19: istore_1
      20: aload_0
      21: checkcast     #24                 // class java/lang/Iterable
      24: astore_2
      25: iconst_0
      26: istore_3
      27: aload_2
      28: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        4
      35: aload         4
      37: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          186
      45: aload         4
      47: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        5
      54: aload         5
      56: checkcast     #40                 // class java/lang/String
      59: astore        6
      61: iconst_0
      62: istore        7
      64: aload         6
      66: checkcast     #42                 // class java/lang/CharSequence
      69: iconst_1
      70: anewarray     #40                 // class java/lang/String
      73: astore        8
      75: aload         8
      77: iconst_0
      78: ldc           #44                 // String
      80: aastore
      81: aload         8
      83: iconst_0
      84: iconst_0
      85: bipush        6
      87: aconst_null
      88: invokestatic  #50                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      91: astore        9
      93: aload         9
      95: iconst_0
      96: invokeinterface #56,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     101: checkcast     #40                 // class java/lang/String
     104: astore        8
     106: aload         9
     108: iconst_1
     109: invokeinterface #56,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     114: checkcast     #40                 // class java/lang/String
     117: astore        10
     119: aload         8
     121: invokestatic  #60                 // Method map:(Ljava/lang/String;)Ljava/lang/String;
     124: aload         10
     126: invokestatic  #60                 // Method map:(Ljava/lang/String;)Ljava/lang/String;
     129: invokestatic  #64                 // Method score:(Ljava/lang/String;Ljava/lang/String;)I
     132: istore        11
     134: iload_1
     135: iload         11
     137: iadd
     138: istore_1
     139: new           #66                 // class java/lang/StringBuilder
     142: dup
     143: invokespecial #68                 // Method java/lang/StringBuilder."<init>":()V
     146: aload         8
     148: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     151: bipush        32
     153: invokevirtual #75                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     156: aload         10
     158: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     161: ldc           #77                 // String :
     163: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     166: iload         11
     168: invokevirtual #80                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     171: invokevirtual #84                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     174: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     177: swap
     178: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     181: nop
     182: nop
     183: goto          35
     186: nop
     187: new           #66                 // class java/lang/StringBuilder
     190: dup
     191: invokespecial #68                 // Method java/lang/StringBuilder."<init>":()V
     194: ldc           #98                 // String Total Score:
     196: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     199: iload_1
     200: invokevirtual #80                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     203: invokevirtual #84                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     206: getstatic     #90                 // Field java/lang/System.out:Ljava/io/PrintStream;
     209: swap
     210: invokevirtual #96                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     213: return

  public static final int score(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #114                // String theirs
       3: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #121                // String mine
       9: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: aload_3
      17: invokevirtual #125                // Method java/lang/String.hashCode:()I
      20: lookupswitch  { // 3
            -591277001: 68
               2552709: 56
              76882284: 80
               default: 107
          }
      56: aload_3
      57: ldc           #127                // String Rock
      59: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      62: ifne          92
      65: goto          107
      68: aload_3
      69: ldc           #133                // String Scissors
      71: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      74: ifne          104
      77: goto          107
      80: aload_3
      81: ldc           #135                // String Paper
      83: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      86: ifne          98
      89: goto          107
      92: iinc          2, 1
      95: goto          107
      98: iinc          2, 2
     101: goto          107
     104: iinc          2, 3
     107: aload_0
     108: aload_1
     109: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     112: ifeq          119
     115: iload_2
     116: iconst_3
     117: iadd
     118: ireturn
     119: aload_0
     120: ldc           #127                // String Rock
     122: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     125: ifeq          137
     128: aload_1
     129: ldc           #135                // String Paper
     131: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     134: ifne          173
     137: aload_0
     138: ldc           #135                // String Paper
     140: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     143: ifeq          155
     146: aload_1
     147: ldc           #133                // String Scissors
     149: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     152: ifne          173
     155: aload_0
     156: ldc           #133                // String Scissors
     158: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     161: ifeq          178
     164: aload_1
     165: ldc           #127                // String Rock
     167: invokestatic  #139                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     170: ifeq          178
     173: iload_2
     174: bipush        6
     176: iadd
     177: ireturn
     178: iload_2
     179: ireturn

  public static final java.lang.String map(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #141                // String move
       3: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_1
       8: aload_1
       9: invokevirtual #125                // Method java/lang/String.hashCode:()I
      12: lookupswitch  { // 6
                    65: 72
                    66: 84
                    67: 96
                    88: 108
                    89: 120
                    90: 132
               default: 153
          }
      72: aload_1
      73: ldc           #143                // String A
      75: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      78: ifne          144
      81: goto          153
      84: aload_1
      85: ldc           #145                // String B
      87: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      90: ifne          147
      93: goto          153
      96: aload_1
      97: ldc           #147                // String C
      99: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     102: ifne          150
     105: goto          153
     108: aload_1
     109: ldc           #149                // String X
     111: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     114: ifne          144
     117: goto          153
     120: aload_1
     121: ldc           #151                // String Y
     123: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     126: ifne          147
     129: goto          153
     132: aload_1
     133: ldc           #153                // String Z
     135: invokevirtual #131                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     138: ifne          150
     141: goto          153
     144: ldc           #127                // String Rock
     146: areturn
     147: ldc           #135                // String Paper
     149: areturn
     150: ldc           #133                // String Scissors
     152: areturn
     153: ldc           #155                // String
     155: areturn

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