// https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem

fun main() {

    val string = readLine().orEmpty()
    println(if (isValid(string)) "YES" else "NO")
}

fun isValid(string: String): Boolean {

    if (string.length <= 3) return true

    val charFreq = IntArray('z' - 'a' + 1)
    for (char in string) charFreq[char - 'a']++

    val metaFreq = mutableMapOf<Int, Int>()
    for (frequency in charFreq) {
        if (frequency != 0) metaFreq[frequency] = metaFreq.getOrDefault(frequency, 0) + 1
    }

    return when (metaFreq.keys.size) {
        1 -> true
        2 -> {
            val (first, second) = metaFreq.keys.toList()
            if ((first == 1 && metaFreq[first] == 1) || (second == 1 && metaFreq[second] == 1)) true
            else Math.abs(first - second) == 1 && (metaFreq[first] == 1 || metaFreq[second] == 1)
        }
        else -> false
    }
}

Compiled from "SherlockAndTheValidString.kt"
public final class SherlockAndTheValidStringKt {
  public static final void main();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: ifnonnull     10
       7: pop
       8: ldc           #14                 // String
      10: astore_0
      11: aload_0
      12: invokestatic  #18                 // Method isValid:(Ljava/lang/String;)Z
      15: ifeq          23
      18: ldc           #20                 // String YES
      20: goto          25
      23: ldc           #22                 // String NO
      25: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: swap
      29: invokevirtual #34                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      32: return

  public static final boolean isValid(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #40                 // String string
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #50                 // Method java/lang/String.length:()I
      10: iconst_3
      11: if_icmpgt     16
      14: iconst_1
      15: ireturn
      16: bipush        26
      18: newarray       int
      20: astore_1
      21: iconst_0
      22: istore_2
      23: aload_0
      24: invokevirtual #50                 // Method java/lang/String.length:()I
      27: istore_3
      28: iload_2
      29: iload_3
      30: if_icmpge     67
      33: aload_0
      34: iload_2
      35: invokevirtual #54                 // Method java/lang/String.charAt:(I)C
      38: istore        4
      40: iload         4
      42: bipush        97
      44: isub
      45: istore        5
      47: aload_1
      48: iload         5
      50: iaload
      51: istore        6
      53: aload_1
      54: iload         5
      56: iload         6
      58: iconst_1
      59: iadd
      60: iastore
      61: iinc          2, 1
      64: goto          28
      67: new           #56                 // class java/util/LinkedHashMap
      70: dup
      71: invokespecial #59                 // Method java/util/LinkedHashMap."<init>":()V
      74: checkcast     #61                 // class java/util/Map
      77: astore_2
      78: iconst_0
      79: istore_3
      80: aload_1
      81: arraylength
      82: istore        4
      84: iload_3
      85: iload         4
      87: if_icmpge     145
      90: aload_1
      91: iload_3
      92: iaload
      93: istore        5
      95: iload         5
      97: ifeq          139
     100: iload         5
     102: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: aload_2
     106: swap
     107: aload_2
     108: iload         5
     110: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: iconst_0
     114: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: invokeinterface #71,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     122: checkcast     #73                 // class java/lang/Number
     125: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     128: iconst_1
     129: iadd
     130: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     133: invokeinterface #79,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     138: pop
     139: iinc          3, 1
     142: goto          84
     145: aload_2
     146: invokeinterface #83,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     151: invokeinterface #88,  1           // InterfaceMethod java/util/Set.size:()I
     156: tableswitch   { // 1 to 2
                     1: 180
                     2: 184
               default: 398
          }
     180: iconst_1
     181: goto          399
     184: aload_2
     185: invokeinterface #83,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     190: checkcast     #90                 // class java/lang/Iterable
     193: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     196: astore        4
     198: aload         4
     200: iconst_0
     201: invokeinterface #102,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     206: checkcast     #73                 // class java/lang/Number
     209: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     212: istore        5
     214: aload         4
     216: iconst_1
     217: invokeinterface #102,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     222: checkcast     #73                 // class java/lang/Number
     225: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     228: istore        6
     230: iload         5
     232: iconst_1
     233: if_icmpne     269
     236: aload_2
     237: iload         5
     239: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     242: invokeinterface #105,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     247: checkcast     #63                 // class java/lang/Integer
     250: iconst_1
     251: istore        7
     253: dup
     254: ifnonnull     261
     257: pop
     258: goto          269
     261: invokevirtual #106                // Method java/lang/Integer.intValue:()I
     264: iload         7
     266: if_icmpeq     308
     269: iload         6
     271: iconst_1
     272: if_icmpne     312
     275: aload_2
     276: iload         6
     278: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     281: invokeinterface #105,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     286: checkcast     #63                 // class java/lang/Integer
     289: iconst_1
     290: istore        7
     292: dup
     293: ifnonnull     300
     296: pop
     297: goto          312
     300: invokevirtual #106                // Method java/lang/Integer.intValue:()I
     303: iload         7
     305: if_icmpne     312
     308: iconst_1
     309: goto          399
     312: iload         5
     314: iload         6
     316: isub
     317: invokestatic  #112                // Method java/lang/Math.abs:(I)I
     320: iconst_1
     321: if_icmpne     394
     324: aload_2
     325: iload         5
     327: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     330: invokeinterface #105,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     335: checkcast     #63                 // class java/lang/Integer
     338: iconst_1
     339: istore        7
     341: dup
     342: ifnonnull     349
     345: pop
     346: goto          357
     349: invokevirtual #106                // Method java/lang/Integer.intValue:()I
     352: iload         7
     354: if_icmpeq     390
     357: aload_2
     358: iload         6
     360: invokestatic  #67                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     363: invokeinterface #105,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     368: checkcast     #63                 // class java/lang/Integer
     371: iconst_1
     372: istore        7
     374: dup
     375: ifnonnull     382
     378: pop
     379: goto          394
     382: invokevirtual #106                // Method java/lang/Integer.intValue:()I
     385: iload         7
     387: if_icmpne     394
     390: iconst_1
     391: goto          399
     394: iconst_0
     395: goto          399
     398: iconst_0
     399: ireturn

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


class LongestPalindromeSolution {
    fun longestPalindrome(s: String): String {
      var chars = s.toCharArray()
      val sourceLength = s.length
      var maxLength = 0
      var maxLeft = 0
      var maxRight = 0
      for (l in 0 until sourceLength) {
        if (maxLength > sourceLength - l) {
          break
        }
        test@ for (r in sourceLength - 1 downTo l) {
          val targetLength = r - l + 1
          for (i in 0 until targetLength / 2) {
            if (chars[l + i] != chars[r - i]) {
              continue@test
            }
          }
          if (maxLength < targetLength) {
            maxLength = targetLength
            maxLeft = l
            maxRight = r
            break
          }
        }
      }
      return s.substring(maxLeft, maxRight + 1)
    }

    fun isPalindrome(chars: CharArray, l : Int, r: Int): Boolean {
      val length = r - l + 1
      for (i in 0 until length / 2) {
        if (chars[l + i] != chars[r - i]) {
          return false
        }
      }
      return true
    }
}

fun main(args: Array<String>) {
  println(LongestPalindromeSolution().longestPalindrome("abbccbbdl"))
}

Compiled from "LongestPalindrome.kt"
public final class LongestPalindromeKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class LongestPalindromeSolution
       9: dup
      10: invokespecial #21                 // Method LongestPalindromeSolution."<init>":()V
      13: ldc           #23                 // String abbccbbdl
      15: invokevirtual #27                 // Method LongestPalindromeSolution.longestPalindrome:(Ljava/lang/String;)Ljava/lang/String;
      18: getstatic     #33                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #39                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: return
}


class LengthOfLongestSubstringSolution {
    fun lengthOfLongestSubstring(s: String): Int {
      var set = hashSetOf<Char>()
      var maxLength = 0
      val size = s.length

      s.forEachIndexed { index, c ->
        set.clear()
        var pos = index + 1
        set.add(c)
        var next : Char? = if (pos < size) s.get(pos) else null
        while (next != null) {
          if (set.contains(next)) {
            break
          }
          set.add(next)
          pos++
          next = if (pos < size) s.get(pos) else null
        }
        if (set.size > maxLength) {
          maxLength = set.size
        }
      }
      return maxLength
    }
}

class LengthOfLongestSubstringSolution2 {
    fun lengthOfLongestSubstring(s: String): Int {
      var maxLength = 0
      var hashMap = hashMapOf<Char, Int>()
      var currentLength = 0
      for (i in 0 until s.length) {
        val c = s.get(i)
        val preIndex = hashMap[c]
        hashMap[c] = i
        currentLength = if (preIndex == null || i - preIndex > currentLength) (currentLength + 1) else (i - preIndex)
        if (currentLength > maxLength) {
          maxLength = currentLength
        }
      }

      return maxLength
    }
}

fun main(args: Array<String>) {
  println(LengthOfLongestSubstringSolution2().lengthOfLongestSubstring("abba"))
}

Compiled from "LengthOfLongestSubstring.kt"
public final class LengthOfLongestSubstringKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class LengthOfLongestSubstringSolution2
       9: dup
      10: invokespecial #21                 // Method LengthOfLongestSubstringSolution2."<init>":()V
      13: ldc           #23                 // String abba
      15: invokevirtual #27                 // Method LengthOfLongestSubstringSolution2.lengthOfLongestSubstring:(Ljava/lang/String;)I
      18: istore_1
      19: getstatic     #33                 // Field java/lang/System.out:Ljava/io/PrintStream;
      22: iload_1
      23: invokevirtual #39                 // Method java/io/PrintStream.println:(I)V
      26: return
}


class FindMedianSortedArraysSolution {
    fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
      var i1 = 0
      var i2 = 0
      var length1 = nums1.size
      var length2 = nums2.size
      var sortedSize = length1 + length2
      var sortedArray = IntArray(sortedSize)
      var k = 0
      while (i1 < length1 || i2 < length2) {
        var e1 = if (i1 < length1)nums1[i1] else null
        var e2 = if (i2 < length2)nums2[i2] else null
        if (e2 == null || (e1 != null && e1 < e2)) {
          sortedArray[k] = e1!!
          i1++
        } else {
          sortedArray[k] = e2
          i2++
        }
        k++
      }

      if (sortedSize > 1 && sortedSize % 2 == 0) {
        return (sortedArray[sortedSize / 2] + sortedArray[sortedSize / 2 - 1]) / 2.0
      } else {
        return sortedArray[sortedSize / 2].toDouble()
      }

    }
}

fun main(args: Array<String>) {
  println(FindMedianSortedArraysSolution().findMedianSortedArrays(intArrayOf(), intArrayOf(2,3)))
}

Compiled from "FineMedianSortedArrays.kt"
public final class FineMedianSortedArraysKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class FindMedianSortedArraysSolution
       9: dup
      10: invokespecial #21                 // Method FindMedianSortedArraysSolution."<init>":()V
      13: iconst_0
      14: newarray       int
      16: iconst_2
      17: newarray       int
      19: astore_1
      20: aload_1
      21: iconst_0
      22: iconst_2
      23: iastore
      24: aload_1
      25: iconst_1
      26: iconst_3
      27: iastore
      28: aload_1
      29: invokevirtual #25                 // Method FindMedianSortedArraysSolution.findMedianSortedArrays:([I[I)D
      32: dstore_1
      33: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: dload_1
      37: invokevirtual #37                 // Method java/io/PrintStream.println:(D)V
      40: return
}


import java.io.File

fun main() {
    fun part1(input: List<String>): Int {
        var duplicates = 0

        for (line in input) {
            val first = line.split(",")[0].split("-")
            val second = line.split(",")[1].split("-")

            if ((second[0].toInt() in first[0].toInt()..first[1].toInt() &&
                            second[1].toInt() in first[0].toInt()..first[1].toInt()) ||
                            (first[0].toInt() in second[0].toInt()..second[1].toInt() &&
                                    first[1].toInt() in second[0].toInt()..second[1].toInt())
            ) {
                duplicates++
            }
        }

        return duplicates
    }

    fun part2(input: List<String>): Int {
        var duplicates = 0

        for (line in input) {
            val first = line.split(",")[0].split("-")
            val second = line.split(",")[1].split("-")

            if (second[0].toInt() in first[0].toInt()..first[1].toInt() ||
                            second[1].toInt() in first[0].toInt()..first[1].toInt() ||
                            first[0].toInt() in second[0].toInt()..second[1].toInt() ||
                            first[1].toInt() in second[0].toInt()..second[1].toInt()
            ) {
                duplicates++
            }
        }

        return duplicates
    }

    val testInput = File("input", "Day04_test.txt").readLines()
    val input = File("input", "Day04.txt").readLines()

    val part1TestOutput = part1(testInput)
    check(part1TestOutput == 2)
    println(part1(input))

    val part2TestOutput = part2(testInput)
    check(part2TestOutput == 4)
    println(part2(input))
}

Compiled from "Day04.kt"
public final class Day04Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String input
       6: ldc           #12                 // String Day04_test.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: new           #8                  // class java/io/File
      21: dup
      22: ldc           #10                 // String input
      24: ldc           #24                 // String Day04.txt
      26: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      29: aconst_null
      30: iconst_1
      31: aconst_null
      32: invokestatic  #22                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      35: astore_1
      36: aload_0
      37: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      40: istore_2
      41: iload_2
      42: iconst_2
      43: if_icmpne     50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: ifne          64
      54: new           #30                 // class java/lang/IllegalStateException
      57: dup
      58: ldc           #32                 // String Check failed.
      60: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      63: athrow
      64: aload_1
      65: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      68: istore_3
      69: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
      72: iload_3
      73: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
      76: aload_0
      77: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
      80: istore_3
      81: iload_3
      82: iconst_4
      83: if_icmpne     90
      86: iconst_1
      87: goto          91
      90: iconst_0
      91: ifne          104
      94: new           #30                 // class java/lang/IllegalStateException
      97: dup
      98: ldc           #32                 // String Check failed.
     100: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     103: athrow
     104: aload_1
     105: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
     108: istore        4
     110: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
     113: iload         4
     115: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
     118: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       8: astore_2
       9: aload_2
      10: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      15: ifeq          448
      18: aload_2
      19: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      24: checkcast     #79                 // class java/lang/String
      27: astore_3
      28: aload_3
      29: checkcast     #81                 // class java/lang/CharSequence
      32: iconst_1
      33: anewarray     #79                 // class java/lang/String
      36: astore        5
      38: aload         5
      40: iconst_0
      41: ldc           #83                 // String ,
      43: aastore
      44: aload         5
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: iconst_0
      55: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #81                 // class java/lang/CharSequence
      63: iconst_1
      64: anewarray     #79                 // class java/lang/String
      67: astore        5
      69: aload         5
      71: iconst_0
      72: ldc           #95                 // String -
      74: aastore
      75: aload         5
      77: iconst_0
      78: iconst_0
      79: bipush        6
      81: aconst_null
      82: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      85: astore        4
      87: aload_3
      88: checkcast     #81                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #79                 // class java/lang/String
      95: astore        6
      97: aload         6
      99: iconst_0
     100: ldc           #83                 // String ,
     102: aastore
     103: aload         6
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: iconst_1
     114: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     119: checkcast     #81                 // class java/lang/CharSequence
     122: iconst_1
     123: anewarray     #79                 // class java/lang/String
     126: astore        6
     128: aload         6
     130: iconst_0
     131: ldc           #95                 // String -
     133: aastore
     134: aload         6
     136: iconst_0
     137: iconst_0
     138: bipush        6
     140: aconst_null
     141: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     144: astore        5
     146: aload         4
     148: iconst_0
     149: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     154: checkcast     #79                 // class java/lang/String
     157: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     160: istore        6
     162: aload         4
     164: iconst_1
     165: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     170: checkcast     #79                 // class java/lang/String
     173: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     176: istore        7
     178: aload         5
     180: iconst_0
     181: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #79                 // class java/lang/String
     189: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     192: istore        8
     194: iload         6
     196: iload         8
     198: if_icmpgt     216
     201: iload         8
     203: iload         7
     205: if_icmpgt     212
     208: iconst_1
     209: goto          217
     212: iconst_0
     213: goto          217
     216: iconst_0
     217: ifeq          294
     220: aload         4
     222: iconst_0
     223: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     228: checkcast     #79                 // class java/lang/String
     231: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     234: istore        6
     236: aload         4
     238: iconst_1
     239: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     244: checkcast     #79                 // class java/lang/String
     247: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     250: istore        7
     252: aload         5
     254: iconst_1
     255: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     260: checkcast     #79                 // class java/lang/String
     263: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     266: istore        8
     268: iload         6
     270: iload         8
     272: if_icmpgt     290
     275: iload         8
     277: iload         7
     279: if_icmpgt     286
     282: iconst_1
     283: goto          291
     286: iconst_0
     287: goto          291
     290: iconst_0
     291: ifne          442
     294: aload         5
     296: iconst_0
     297: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     302: checkcast     #79                 // class java/lang/String
     305: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     308: istore        6
     310: aload         5
     312: iconst_1
     313: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     318: checkcast     #79                 // class java/lang/String
     321: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     324: istore        7
     326: aload         4
     328: iconst_0
     329: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     334: checkcast     #79                 // class java/lang/String
     337: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     340: istore        8
     342: iload         6
     344: iload         8
     346: if_icmpgt     364
     349: iload         8
     351: iload         7
     353: if_icmpgt     360
     356: iconst_1
     357: goto          365
     360: iconst_0
     361: goto          365
     364: iconst_0
     365: ifeq          9
     368: aload         5
     370: iconst_0
     371: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     376: checkcast     #79                 // class java/lang/String
     379: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     382: istore        6
     384: aload         5
     386: iconst_1
     387: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     392: checkcast     #79                 // class java/lang/String
     395: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     398: istore        7
     400: aload         4
     402: iconst_1
     403: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     408: checkcast     #79                 // class java/lang/String
     411: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     414: istore        8
     416: iload         6
     418: iload         8
     420: if_icmpgt     438
     423: iload         8
     425: iload         7
     427: if_icmpgt     434
     430: iconst_1
     431: goto          439
     434: iconst_0
     435: goto          439
     438: iconst_0
     439: ifeq          9
     442: iinc          1, 1
     445: goto          9
     448: iload_1
     449: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       8: astore_2
       9: aload_2
      10: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      15: ifeq          448
      18: aload_2
      19: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      24: checkcast     #79                 // class java/lang/String
      27: astore_3
      28: aload_3
      29: checkcast     #81                 // class java/lang/CharSequence
      32: iconst_1
      33: anewarray     #79                 // class java/lang/String
      36: astore        5
      38: aload         5
      40: iconst_0
      41: ldc           #83                 // String ,
      43: aastore
      44: aload         5
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: iconst_0
      55: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #81                 // class java/lang/CharSequence
      63: iconst_1
      64: anewarray     #79                 // class java/lang/String
      67: astore        5
      69: aload         5
      71: iconst_0
      72: ldc           #95                 // String -
      74: aastore
      75: aload         5
      77: iconst_0
      78: iconst_0
      79: bipush        6
      81: aconst_null
      82: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      85: astore        4
      87: aload_3
      88: checkcast     #81                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #79                 // class java/lang/String
      95: astore        6
      97: aload         6
      99: iconst_0
     100: ldc           #83                 // String ,
     102: aastore
     103: aload         6
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: iconst_1
     114: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     119: checkcast     #81                 // class java/lang/CharSequence
     122: iconst_1
     123: anewarray     #79                 // class java/lang/String
     126: astore        6
     128: aload         6
     130: iconst_0
     131: ldc           #95                 // String -
     133: aastore
     134: aload         6
     136: iconst_0
     137: iconst_0
     138: bipush        6
     140: aconst_null
     141: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     144: astore        5
     146: aload         4
     148: iconst_0
     149: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     154: checkcast     #79                 // class java/lang/String
     157: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     160: istore        6
     162: aload         4
     164: iconst_1
     165: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     170: checkcast     #79                 // class java/lang/String
     173: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     176: istore        7
     178: aload         5
     180: iconst_0
     181: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #79                 // class java/lang/String
     189: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     192: istore        8
     194: iload         6
     196: iload         8
     198: if_icmpgt     216
     201: iload         8
     203: iload         7
     205: if_icmpgt     212
     208: iconst_1
     209: goto          217
     212: iconst_0
     213: goto          217
     216: iconst_0
     217: ifne          442
     220: aload         4
     222: iconst_0
     223: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     228: checkcast     #79                 // class java/lang/String
     231: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     234: istore        6
     236: aload         4
     238: iconst_1
     239: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     244: checkcast     #79                 // class java/lang/String
     247: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     250: istore        7
     252: aload         5
     254: iconst_1
     255: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     260: checkcast     #79                 // class java/lang/String
     263: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     266: istore        8
     268: iload         6
     270: iload         8
     272: if_icmpgt     290
     275: iload         8
     277: iload         7
     279: if_icmpgt     286
     282: iconst_1
     283: goto          291
     286: iconst_0
     287: goto          291
     290: iconst_0
     291: ifne          442
     294: aload         5
     296: iconst_0
     297: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     302: checkcast     #79                 // class java/lang/String
     305: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     308: istore        6
     310: aload         5
     312: iconst_1
     313: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     318: checkcast     #79                 // class java/lang/String
     321: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     324: istore        7
     326: aload         4
     328: iconst_0
     329: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     334: checkcast     #79                 // class java/lang/String
     337: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     340: istore        8
     342: iload         6
     344: iload         8
     346: if_icmpgt     364
     349: iload         8
     351: iload         7
     353: if_icmpgt     360
     356: iconst_1
     357: goto          365
     360: iconst_0
     361: goto          365
     364: iconst_0
     365: ifne          442
     368: aload         5
     370: iconst_0
     371: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     376: checkcast     #79                 // class java/lang/String
     379: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     382: istore        6
     384: aload         5
     386: iconst_1
     387: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     392: checkcast     #79                 // class java/lang/String
     395: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     398: istore        7
     400: aload         4
     402: iconst_1
     403: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     408: checkcast     #79                 // class java/lang/String
     411: invokestatic  #101                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     414: istore        8
     416: iload         6
     418: iload         8
     420: if_icmpgt     438
     423: iload         8
     425: iload         7
     427: if_icmpgt     434
     430: iconst_1
     431: goto          439
     434: iconst_0
     435: goto          439
     438: iconst_0
     439: ifeq          9
     442: iinc          1, 1
     445: goto          9
     448: iload_1
     449: ireturn
}


import java.io.File

fun main() {
    fun part1(input: List<String>): Int {
        var priorities = 0

        for (line in input) {
            val firstHalf = line.substring(0..line.length / 2 - 1).toSet()
            val secondHalf = line.substring(line.length / 2).toSet()
            val intersect = (firstHalf intersect secondHalf).first()

            if (intersect.isLowerCase()) {
                priorities += intersect - 'a' + 1
            } else {
                priorities += intersect - 'A' + 27
            }
        }

        return priorities
    }

    fun part2(input: List<String>): Int {
        var priorities = 0

        for (index in 0..input.size - 1 step 3) {
            val group1 = input[index].substring(0..input[index].length - 1).toSet()
            val group2 = input[index + 1].substring(0..input[index + 1].length - 1).toSet()
            val group3 = input[index + 2].substring(0..input[index + 2].length - 1).toSet()
            val intersect = (group1 intersect group2 intersect group3).first()

            if (intersect.isLowerCase()) {
                priorities += intersect - 'a' + 1
            } else {
                priorities += intersect - 'A' + 27
            }
        }

        return priorities
    }

    val testInput = File("input", "Day03_test.txt").readLines()
    val input = File("input", "Day03.txt").readLines()

    val part1TestOutput = part1(testInput)
    check(part1TestOutput == 157)
    println(part1(input))

    val part2TestOutput = part2(testInput)
    check(part2TestOutput == 70)
    println(part2(input))
}

Compiled from "Day03.kt"
public final class Day03Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String input
       6: ldc           #12                 // String Day03_test.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: new           #8                  // class java/io/File
      21: dup
      22: ldc           #10                 // String input
      24: ldc           #24                 // String Day03.txt
      26: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      29: aconst_null
      30: iconst_1
      31: aconst_null
      32: invokestatic  #22                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      35: astore_1
      36: aload_0
      37: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      40: istore_2
      41: iload_2
      42: sipush        157
      45: if_icmpne     52
      48: iconst_1
      49: goto          53
      52: iconst_0
      53: ifne          66
      56: new           #30                 // class java/lang/IllegalStateException
      59: dup
      60: ldc           #32                 // String Check failed.
      62: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      65: athrow
      66: aload_1
      67: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      70: istore_3
      71: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
      74: iload_3
      75: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
      78: aload_0
      79: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
      82: istore_3
      83: iload_3
      84: bipush        70
      86: if_icmpne     93
      89: iconst_1
      90: goto          94
      93: iconst_0
      94: ifne          107
      97: new           #30                 // class java/lang/IllegalStateException
     100: dup
     101: ldc           #32                 // String Check failed.
     103: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     106: athrow
     107: aload_1
     108: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
     111: istore        4
     113: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
     116: iload         4
     118: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
     121: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       8: astore_2
       9: aload_2
      10: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      15: ifeq          142
      18: aload_2
      19: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      24: checkcast     #79                 // class java/lang/String
      27: astore_3
      28: aload_3
      29: new           #81                 // class kotlin/ranges/IntRange
      32: dup
      33: iconst_0
      34: aload_3
      35: invokevirtual #85                 // Method java/lang/String.length:()I
      38: iconst_2
      39: idiv
      40: iconst_1
      41: isub
      42: invokespecial #88                 // Method kotlin/ranges/IntRange."<init>":(II)V
      45: invokestatic  #94                 // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      48: checkcast     #96                 // class java/lang/CharSequence
      51: invokestatic  #100                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      54: astore        4
      56: aload_3
      57: aload_3
      58: invokevirtual #85                 // Method java/lang/String.length:()I
      61: iconst_2
      62: idiv
      63: invokevirtual #103                // Method java/lang/String.substring:(I)Ljava/lang/String;
      66: dup
      67: ldc           #105                // String substring(...)
      69: invokestatic  #111                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      72: checkcast     #96                 // class java/lang/CharSequence
      75: invokestatic  #100                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      78: astore        5
      80: aload         4
      82: checkcast     #113                // class java/lang/Iterable
      85: aload         5
      87: checkcast     #113                // class java/lang/Iterable
      90: invokestatic  #119                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      93: checkcast     #113                // class java/lang/Iterable
      96: invokestatic  #123                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
      99: checkcast     #125                // class java/lang/Character
     102: invokevirtual #129                // Method java/lang/Character.charValue:()C
     105: istore        6
     107: iload         6
     109: invokestatic  #133                // Method java/lang/Character.isLowerCase:(C)Z
     112: ifeq          128
     115: iload_1
     116: iload         6
     118: bipush        97
     120: isub
     121: iconst_1
     122: iadd
     123: iadd
     124: istore_1
     125: goto          9
     128: iload_1
     129: iload         6
     131: bipush        65
     133: isub
     134: bipush        27
     136: iadd
     137: iadd
     138: istore_1
     139: goto          9
     142: iload_1
     143: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokeinterface #145,  1          // InterfaceMethod java/util/List.size:()I
       8: iconst_1
       9: isub
      10: istore_2
      11: iconst_0
      12: istore_3
      13: iconst_0
      14: iload_2
      15: iconst_3
      16: invokestatic  #151                // Method kotlin/internal/ProgressionUtilKt.getProgressionLastElement:(III)I
      19: istore        4
      21: iload_3
      22: iload         4
      24: if_icmpgt     249
      27: aload_0
      28: iload_3
      29: invokeinterface #155,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #79                 // class java/lang/String
      37: new           #81                 // class kotlin/ranges/IntRange
      40: dup
      41: iconst_0
      42: aload_0
      43: iload_3
      44: invokeinterface #155,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      49: checkcast     #79                 // class java/lang/String
      52: invokevirtual #85                 // Method java/lang/String.length:()I
      55: iconst_1
      56: isub
      57: invokespecial #88                 // Method kotlin/ranges/IntRange."<init>":(II)V
      60: invokestatic  #94                 // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      63: checkcast     #96                 // class java/lang/CharSequence
      66: invokestatic  #100                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
      69: astore        5
      71: aload_0
      72: iload_3
      73: iconst_1
      74: iadd
      75: invokeinterface #155,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      80: checkcast     #79                 // class java/lang/String
      83: new           #81                 // class kotlin/ranges/IntRange
      86: dup
      87: iconst_0
      88: aload_0
      89: iload_3
      90: iconst_1
      91: iadd
      92: invokeinterface #155,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      97: checkcast     #79                 // class java/lang/String
     100: invokevirtual #85                 // Method java/lang/String.length:()I
     103: iconst_1
     104: isub
     105: invokespecial #88                 // Method kotlin/ranges/IntRange."<init>":(II)V
     108: invokestatic  #94                 // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
     111: checkcast     #96                 // class java/lang/CharSequence
     114: invokestatic  #100                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     117: astore        6
     119: aload_0
     120: iload_3
     121: iconst_2
     122: iadd
     123: invokeinterface #155,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     128: checkcast     #79                 // class java/lang/String
     131: new           #81                 // class kotlin/ranges/IntRange
     134: dup
     135: iconst_0
     136: aload_0
     137: iload_3
     138: iconst_2
     139: iadd
     140: invokeinterface #155,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     145: checkcast     #79                 // class java/lang/String
     148: invokevirtual #85                 // Method java/lang/String.length:()I
     151: iconst_1
     152: isub
     153: invokespecial #88                 // Method kotlin/ranges/IntRange."<init>":(II)V
     156: invokestatic  #94                 // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
     159: checkcast     #96                 // class java/lang/CharSequence
     162: invokestatic  #100                // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     165: astore        7
     167: aload         5
     169: checkcast     #113                // class java/lang/Iterable
     172: aload         6
     174: checkcast     #113                // class java/lang/Iterable
     177: invokestatic  #119                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     180: checkcast     #113                // class java/lang/Iterable
     183: aload         7
     185: checkcast     #113                // class java/lang/Iterable
     188: invokestatic  #119                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     191: checkcast     #113                // class java/lang/Iterable
     194: invokestatic  #123                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     197: checkcast     #125                // class java/lang/Character
     200: invokevirtual #129                // Method java/lang/Character.charValue:()C
     203: istore        8
     205: iload         8
     207: invokestatic  #133                // Method java/lang/Character.isLowerCase:(C)Z
     210: ifeq          226
     213: iload_1
     214: iload         8
     216: bipush        97
     218: isub
     219: iconst_1
     220: iadd
     221: iadd
     222: istore_1
     223: goto          237
     226: iload_1
     227: iload         8
     229: bipush        65
     231: isub
     232: bipush        27
     234: iadd
     235: iadd
     236: istore_1
     237: iload_3
     238: iload         4
     240: if_icmpeq     249
     243: iinc          3, 3
     246: goto          27
     249: iload_1
     250: ireturn
}


import java.io.File

fun main() {
    fun part1(input: List<String>): Int {
        var points = 0

        for (line in input) {
            val them = line.split(" ")[0]
            val you = line.split(" ")[1]

            val theirValue =
                    when (them) {
                        "A" -> 1
                        "B" -> 2
                        "C" -> 3
                        else -> 0
                    }

            val yourValue =
                    when (you) {
                        "X" -> 1
                        "Y" -> 2
                        "Z" -> 3
                        else -> 0
                    }

            if (theirValue == yourValue) {
                points += 3
            } else if (theirValue + 1 == yourValue || (theirValue == 3 && yourValue == 1)) {
                points += 6
            }

            points += yourValue
        }

        return points
    }

    fun part2(input: List<String>): Int {
        var points = 0

        for (line in input) {
            val them = line.split(" ")[0]
            val you = line.split(" ")[1]

            val theirValue =
                    when (them) {
                        "A" -> 1
                        "B" -> 2
                        "C" -> 3
                        else -> 0
                    }

            if (you == "Y") {
                points += theirValue
                points += 3
            } else if (you == "Z") {
                if (theirValue != 3) {
                    points += theirValue + 1
                } else {
                    points += 1
                }
                points += 6
            } else {
                if (theirValue != 1) {
                    points += theirValue - 1
                } else {
                    points += 3
                }
            }
        }

        return points
    }

    val testInput = File("input", "Day02_test.txt").readLines()
    val input = File("input", "Day02.txt").readLines()

    val part1TestOutput = part1(testInput)
    check(part1TestOutput == 15)
    println(part1(input))

    val part2TestOutput = part2(testInput)
    check(part2TestOutput == 12)
    println(part2(input))
}

Compiled from "Day02.kt"
public final class Day02Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String input
       6: ldc           #12                 // String Day02_test.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: new           #8                  // class java/io/File
      21: dup
      22: ldc           #10                 // String input
      24: ldc           #24                 // String Day02.txt
      26: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      29: aconst_null
      30: iconst_1
      31: aconst_null
      32: invokestatic  #22                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      35: astore_1
      36: aload_0
      37: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      40: istore_2
      41: iload_2
      42: bipush        15
      44: if_icmpne     51
      47: iconst_1
      48: goto          52
      51: iconst_0
      52: ifne          65
      55: new           #30                 // class java/lang/IllegalStateException
      58: dup
      59: ldc           #32                 // String Check failed.
      61: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      64: athrow
      65: aload_1
      66: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      69: istore_3
      70: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
      73: iload_3
      74: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
      77: aload_0
      78: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
      81: istore_3
      82: iload_3
      83: bipush        12
      85: if_icmpne     92
      88: iconst_1
      89: goto          93
      92: iconst_0
      93: ifne          106
      96: new           #30                 // class java/lang/IllegalStateException
      99: dup
     100: ldc           #32                 // String Check failed.
     102: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     105: athrow
     106: aload_1
     107: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
     110: istore        4
     112: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
     115: iload         4
     117: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
     120: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       8: astore_2
       9: aload_2
      10: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      15: ifeq          323
      18: aload_2
      19: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      24: checkcast     #79                 // class java/lang/String
      27: astore_3
      28: aload_3
      29: checkcast     #81                 // class java/lang/CharSequence
      32: iconst_1
      33: anewarray     #79                 // class java/lang/String
      36: astore        5
      38: aload         5
      40: iconst_0
      41: ldc           #83                 // String
      43: aastore
      44: aload         5
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: iconst_0
      55: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #79                 // class java/lang/String
      63: astore        4
      65: aload_3
      66: checkcast     #81                 // class java/lang/CharSequence
      69: iconst_1
      70: anewarray     #79                 // class java/lang/String
      73: astore        6
      75: aload         6
      77: iconst_0
      78: ldc           #83                 // String
      80: aastore
      81: aload         6
      83: iconst_0
      84: iconst_0
      85: bipush        6
      87: aconst_null
      88: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      91: iconst_1
      92: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      97: checkcast     #79                 // class java/lang/String
     100: astore        5
     102: aload         4
     104: astore        7
     106: aload         7
     108: invokevirtual #97                 // Method java/lang/String.hashCode:()I
     111: tableswitch   { // 65 to 67
                    65: 136
                    66: 149
                    67: 162
               default: 187
          }
     136: aload         7
     138: ldc           #99                 // String A
     140: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     143: ifne          175
     146: goto          187
     149: aload         7
     151: ldc           #105                // String B
     153: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     156: ifne          179
     159: goto          187
     162: aload         7
     164: ldc           #107                // String C
     166: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     169: ifne          183
     172: goto          187
     175: iconst_1
     176: goto          188
     179: iconst_2
     180: goto          188
     183: iconst_3
     184: goto          188
     187: iconst_0
     188: istore        6
     190: aload         5
     192: astore        8
     194: aload         8
     196: invokevirtual #97                 // Method java/lang/String.hashCode:()I
     199: tableswitch   { // 88 to 90
                    88: 224
                    89: 237
                    90: 250
               default: 275
          }
     224: aload         8
     226: ldc           #109                // String X
     228: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     231: ifne          263
     234: goto          275
     237: aload         8
     239: ldc           #111                // String Y
     241: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     244: ifne          267
     247: goto          275
     250: aload         8
     252: ldc           #113                // String Z
     254: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     257: ifne          271
     260: goto          275
     263: iconst_1
     264: goto          276
     267: iconst_2
     268: goto          276
     271: iconst_3
     272: goto          276
     275: iconst_0
     276: istore        7
     278: iload         6
     280: iload         7
     282: if_icmpne     291
     285: iinc          1, 3
     288: goto          315
     291: iload         6
     293: iconst_1
     294: iadd
     295: iload         7
     297: if_icmpeq     312
     300: iload         6
     302: iconst_3
     303: if_icmpne     315
     306: iload         7
     308: iconst_1
     309: if_icmpne     315
     312: iinc          1, 6
     315: iload_1
     316: iload         7
     318: iadd
     319: istore_1
     320: goto          9
     323: iload_1
     324: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: aload_0
       3: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       8: astore_2
       9: aload_2
      10: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      15: ifeq          268
      18: aload_2
      19: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      24: checkcast     #79                 // class java/lang/String
      27: astore_3
      28: aload_3
      29: checkcast     #81                 // class java/lang/CharSequence
      32: iconst_1
      33: anewarray     #79                 // class java/lang/String
      36: astore        5
      38: aload         5
      40: iconst_0
      41: ldc           #83                 // String
      43: aastore
      44: aload         5
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: iconst_0
      55: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #79                 // class java/lang/String
      63: astore        4
      65: aload_3
      66: checkcast     #81                 // class java/lang/CharSequence
      69: iconst_1
      70: anewarray     #79                 // class java/lang/String
      73: astore        6
      75: aload         6
      77: iconst_0
      78: ldc           #83                 // String
      80: aastore
      81: aload         6
      83: iconst_0
      84: iconst_0
      85: bipush        6
      87: aconst_null
      88: invokestatic  #89                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      91: iconst_1
      92: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      97: checkcast     #79                 // class java/lang/String
     100: astore        5
     102: aload         4
     104: astore        7
     106: aload         7
     108: invokevirtual #97                 // Method java/lang/String.hashCode:()I
     111: tableswitch   { // 65 to 67
                    65: 136
                    66: 149
                    67: 162
               default: 187
          }
     136: aload         7
     138: ldc           #99                 // String A
     140: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     143: ifne          175
     146: goto          187
     149: aload         7
     151: ldc           #105                // String B
     153: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     156: ifne          179
     159: goto          187
     162: aload         7
     164: ldc           #107                // String C
     166: invokevirtual #103                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     169: ifne          183
     172: goto          187
     175: iconst_1
     176: goto          188
     179: iconst_2
     180: goto          188
     183: iconst_3
     184: goto          188
     187: iconst_0
     188: istore        6
     190: aload         5
     192: ldc           #111                // String Y
     194: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     197: ifeq          211
     200: iload_1
     201: iload         6
     203: iadd
     204: istore_1
     205: iinc          1, 3
     208: goto          9
     211: aload         5
     213: ldc           #113                // String Z
     215: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     218: ifeq          246
     221: iload         6
     223: iconst_3
     224: if_icmpeq     237
     227: iload_1
     228: iload         6
     230: iconst_1
     231: iadd
     232: iadd
     233: istore_1
     234: goto          240
     237: iinc          1, 1
     240: iinc          1, 6
     243: goto          9
     246: iload         6
     248: iconst_1
     249: if_icmpeq     262
     252: iload_1
     253: iload         6
     255: iconst_1
     256: isub
     257: iadd
     258: istore_1
     259: goto          9
     262: iinc          1, 3
     265: goto          9
     268: iload_1
     269: ireturn
}


import java.io.File

fun main() {
    fun part1(input: List<String>): Int {
        var globalMax = 0
        var localMax = 0

        for (line in input) {
            if (line != "") {
                localMax = localMax + line.toInt()
            } else {
                if (localMax.compareTo(globalMax) > 0) {
                    globalMax = localMax
                }

                localMax = 0
            }
        }

        return globalMax
    }

    fun part2(input: List<String>): Int {
        var max = ArrayList<Int>()
        var localMax = 0

        for (index in 0..input.size - 1) {
            if (input[index] != "") {
                localMax = localMax + input[index].toInt()
            } else {
                max.add(localMax)

                if (index != input.size - 1) {
                    localMax = 0
                }
            }
        }

        max.add(localMax)
        max.sort()

        return max[max.size - 1] + max[max.size - 2] + max[max.size - 3]
    }

    val testInput = File("input", "Day01_test.txt").readLines()
    val input = File("input", "Day01.txt").readLines()

    val part1TestOutput = part1(testInput)
    check(part1TestOutput == 24000)
    println(part1(input))

    val part2TestOutput = part2(testInput)
    check(part2TestOutput == 45000)
    println(part2(input))
}

Compiled from "Day01.kt"
public final class Day01Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String input
       6: ldc           #12                 // String Day01_test.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: new           #8                  // class java/io/File
      21: dup
      22: ldc           #10                 // String input
      24: ldc           #24                 // String Day01.txt
      26: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      29: aconst_null
      30: iconst_1
      31: aconst_null
      32: invokestatic  #22                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      35: astore_1
      36: aload_0
      37: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      40: istore_2
      41: iload_2
      42: sipush        24000
      45: if_icmpne     52
      48: iconst_1
      49: goto          53
      52: iconst_0
      53: ifne          66
      56: new           #30                 // class java/lang/IllegalStateException
      59: dup
      60: ldc           #32                 // String Check failed.
      62: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      65: athrow
      66: aload_1
      67: invokestatic  #28                 // Method main$part1:(Ljava/util/List;)I
      70: istore_3
      71: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
      74: iload_3
      75: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
      78: aload_0
      79: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
      82: istore_3
      83: iload_3
      84: ldc           #51                 // int 45000
      86: if_icmpne     93
      89: iconst_1
      90: goto          94
      93: iconst_0
      94: ifne          107
      97: new           #30                 // class java/lang/IllegalStateException
     100: dup
     101: ldc           #32                 // String Check failed.
     103: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     106: athrow
     107: aload_1
     108: invokestatic  #50                 // Method main$part2:(Ljava/util/List;)I
     111: istore        4
     113: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
     116: iload         4
     118: invokevirtual #47                 // Method java/io/PrintStream.println:(I)V
     121: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: aload_0
       5: invokeinterface #68,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      10: astore_3
      11: aload_3
      12: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      17: ifeq          67
      20: aload_3
      21: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      26: checkcast     #80                 // class java/lang/String
      29: astore        4
      31: aload         4
      33: ldc           #82                 // String
      35: invokestatic  #88                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      38: ifne          52
      41: iload_2
      42: aload         4
      44: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      47: iadd
      48: istore_2
      49: goto          11
      52: iload_2
      53: iload_1
      54: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      57: ifle          62
      60: iload_2
      61: istore_1
      62: iconst_0
      63: istore_2
      64: goto          11
      67: iload_1
      68: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: new           #104                // class java/util/ArrayList
       3: dup
       4: invokespecial #106                // Method java/util/ArrayList."<init>":()V
       7: astore_1
       8: iconst_0
       9: istore_2
      10: iconst_0
      11: istore_3
      12: aload_0
      13: invokeinterface #110,  1          // InterfaceMethod java/util/List.size:()I
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     89
      26: aload_0
      27: iload_3
      28: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      33: ldc           #82                 // String
      35: invokestatic  #88                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      38: ifne          60
      41: iload_2
      42: aload_0
      43: iload_3
      44: invokeinterface #114,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      49: checkcast     #80                 // class java/lang/String
      52: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      55: iadd
      56: istore_2
      57: goto          83
      60: aload_1
      61: iload_2
      62: invokestatic  #118                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: invokevirtual #122                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      68: pop
      69: iload_3
      70: aload_0
      71: invokeinterface #110,  1          // InterfaceMethod java/util/List.size:()I
      76: iconst_1
      77: isub
      78: if_icmpeq     83
      81: iconst_0
      82: istore_2
      83: iinc          3, 1
      86: goto          20
      89: aload_1
      90: iload_2
      91: invokestatic  #118                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: invokevirtual #122                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      97: pop
      98: aload_1
      99: checkcast     #58                 // class java/util/List
     102: invokestatic  #128                // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     105: aload_1
     106: aload_1
     107: invokevirtual #129                // Method java/util/ArrayList.size:()I
     110: iconst_1
     111: isub
     112: invokevirtual #130                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     115: checkcast     #132                // class java/lang/Number
     118: invokevirtual #135                // Method java/lang/Number.intValue:()I
     121: aload_1
     122: aload_1
     123: invokevirtual #129                // Method java/util/ArrayList.size:()I
     126: iconst_2
     127: isub
     128: invokevirtual #130                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     131: dup
     132: ldc           #137                // String get(...)
     134: invokestatic  #141                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     137: checkcast     #132                // class java/lang/Number
     140: invokevirtual #135                // Method java/lang/Number.intValue:()I
     143: iadd
     144: aload_1
     145: aload_1
     146: invokevirtual #129                // Method java/util/ArrayList.size:()I
     149: iconst_3
     150: isub
     151: invokevirtual #130                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     154: dup
     155: ldc           #137                // String get(...)
     157: invokestatic  #141                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     160: checkcast     #132                // class java/lang/Number
     163: invokevirtual #135                // Method java/lang/Number.intValue:()I
     166: iadd
     167: ireturn
}