package hm.binkley.dice.rolling

import java.util.Objects.hash

sealed class KeepCount(protected val value: Int) {
    override fun toString() = "${this::class.simpleName}($value)"

    override fun equals(other: Any?) = this === other ||
        other is KeepCount &&
        javaClass == other.javaClass &&
        value == other.value

    override fun hashCode() = hash(javaClass, value)

    /** Splits sorted list of results into those to keep and those to drop. */
    protected abstract fun partition(other: List<Int>):
        Pair<List<Int>, List<Int>>

    companion object {
        fun List<Int>.keep(count: KeepCount) = count.partition(this)
    }
}

/**
 * Keeps the highest dice rolls.
 */
class KeepHigh(value: Int) : KeepCount(value) {
    override fun partition(other: List<Int>): Pair<List<Int>, List<Int>> {
        val (kept, dropped) = other.withIndex().partition { (index, _) ->
            other.size - value <= index
        }

        return kept.withoutIndex() to dropped.withoutIndex()
    }
}

/**
 * Keeps the lower middle dice rolls.
 * When there are even/odd numbers of dice, and even/odd numbers to keep:
 * - Even / even -- middle low and high are the same
 * - Even /odd -- picks up an extra low roll
 * - Odd / even -- picks up an extra low roll
 * - Odd / odd -- middle low and high are the same
 */
class KeepMiddleLow(value: Int) : KeepMiddle(value) {
    override fun splitKeep(listEven: Boolean, keepEven: Boolean) =
        if (listEven && keepEven) value / 2 else value / 2 + 1
}

/**
 * Keeps the upper middle dice rolls.
 * When there are even/odd numbers of dice, and even/odd numbers to keep:
 * - Even / even -- middle low and high are the same
 * - Even /odd -- picks up an extra high roll
 * - Odd / even -- picks up an extra high roll
 * - Odd / odd -- middle low and high are the same
 */
class KeepMiddleHigh(value: Int) : KeepMiddle(value) {
    override fun splitKeep(listEven: Boolean, keepEven: Boolean) =
        if (!listEven && !keepEven) value / 2 + 1 else value / 2
}

abstract class KeepMiddle(
    value: Int,
) : KeepCount(value) {
    protected abstract fun splitKeep(
        listEven: Boolean,
        keepEven: Boolean,
    ): Int

    override fun partition(other: List<Int>): Pair<List<Int>, List<Int>> {
        if (0 == value || other.isEmpty())
            return emptyList<Int>() to other

        val listEven = 0 == other.size % 2
        val keepEven = 0 == value % 2

        val lowerSize =
            if (listEven) other.size / 2
            else other.size / 2 + 1
        val lowerKeep = splitKeep(listEven, keepEven)
        val upperKeep = value - lowerKeep

        val (lower, upper) = other.keep(KeepLow(lowerSize))
        val (lowerKept, lowerDropped) = lower.keep(KeepHigh(lowerKeep))
        val (upperKept, upperDropped) = upper.keep(KeepLow(upperKeep))

        return (lowerKept + upperKept) to (lowerDropped + upperDropped)
    }
}

/**
 * Keeps the lowest dice rolls.
 */
class KeepLow(value: Int) : KeepCount(value) {
    override fun partition(other: List<Int>): Pair<List<Int>, List<Int>> {
        val (kept, dropped) = other.withIndex().partition { (index, _) ->
            value > index
        }

        return kept.withoutIndex() to dropped.withoutIndex()
    }
}

private fun <T> List<IndexedValue<T>>.withoutIndex() = map { (_, it) -> it }

Compiled from "KeepCount.kt"
public final class hm.binkley.dice.rolling.KeepCountKt {
  private static final <T> java.util.List<T> withoutIndex(java.util.List<? extends kotlin.collections.IndexedValue<? extends T>>);
    Code:
       0: aload_0
       1: checkcast     #9                  // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #11                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #17                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #21                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #23                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          92
      48: aload         6
      50: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #39                 // class kotlin/collections/IndexedValue
      64: astore        8
      66: astore        11
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokevirtual #42                 // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
      76: astore        10
      78: aload         10
      80: aload         11
      82: swap
      83: invokeinterface #46,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          38
      92: aload         4
      94: checkcast     #48                 // class java/util/List
      97: nop
      98: areturn

  public static final java.util.List access$withoutIndex(java.util.List);
    Code:
       0: aload_0
       1: invokestatic  #65                 // Method withoutIndex:(Ljava/util/List;)Ljava/util/List;
       4: areturn
}

Compiled from "KeepCount.kt"
public abstract class hm.binkley.dice.rolling.KeepCount {
  public static final hm.binkley.dice.rolling.KeepCount$Companion Companion;

  private final int value;

  private hm.binkley.dice.rolling.KeepCount(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field value:I
       9: return

  protected final int getValue();
    Code:
       0: aload_0
       1: getfield      #13                 // Field value:I
       4: ireturn

  public java.lang.String toString();
    Code:
       0: new           #22                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #23                 // Method java/lang/StringBuilder."<init>":()V
       7: aload_0
       8: invokevirtual #27                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      11: invokestatic  #33                 // Method kotlin/jvm/internal/Reflection.getOrCreateKotlinClass:(Ljava/lang/Class;)Lkotlin/reflect/KClass;
      14: invokeinterface #38,  1           // InterfaceMethod kotlin/reflect/KClass.getSimpleName:()Ljava/lang/String;
      19: invokevirtual #42                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: bipush        40
      24: invokevirtual #45                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      27: aload_0
      28: getfield      #13                 // Field value:I
      31: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      34: bipush        41
      36: invokevirtual #45                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      39: invokevirtual #50                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      42: areturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpeq     40
       5: aload_1
       6: instanceof    #2                  // class hm/binkley/dice/rolling/KeepCount
       9: ifeq          44
      12: aload_0
      13: invokevirtual #27                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      16: aload_1
      17: invokevirtual #27                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      20: invokestatic  #59                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      23: ifeq          44
      26: aload_0
      27: getfield      #13                 // Field value:I
      30: aload_1
      31: checkcast     #2                  // class hm/binkley/dice/rolling/KeepCount
      34: getfield      #13                 // Field value:I
      37: if_icmpne     44
      40: iconst_1
      41: goto          45
      44: iconst_0
      45: ireturn

  public int hashCode();
    Code:
       0: iconst_2
       1: anewarray     #4                  // class java/lang/Object
       4: astore_1
       5: aload_1
       6: iconst_0
       7: aload_0
       8: invokevirtual #27                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      11: aastore
      12: aload_1
      13: iconst_1
      14: aload_0
      15: getfield      #13                 // Field value:I
      18: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: aastore
      22: aload_1
      23: invokestatic  #74                 // Method java/util/Objects.hash:([Ljava/lang/Object;)I
      26: ireturn

  protected abstract kotlin.Pair<java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>> partition(java.util.List<java.lang.Integer>);

  public hm.binkley.dice.rolling.KeepCount(int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: iload_1
       2: invokespecial #80                 // Method "<init>":(I)V
       5: return

  static {};
    Code:
       0: new           #85                 // class hm/binkley/dice/rolling/KeepCount$Companion
       3: dup
       4: aconst_null
       5: invokespecial #88                 // Method hm/binkley/dice/rolling/KeepCount$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #92                 // Field Companion:Lhm/binkley/dice/rolling/KeepCount$Companion;
      11: return
}

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

  public final kotlin.Pair<java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>> keep(java.util.List<java.lang.Integer>, hm.binkley.dice.rolling.KeepCount);
    Code:
       0: aload_1
       1: ldc           #16                 // String <this>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #24                 // String count
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_2
      13: aload_1
      14: invokevirtual #30                 // Method hm/binkley/dice/rolling/KeepCount.partition:(Ljava/util/List;)Lkotlin/Pair;
      17: areturn

  public hm.binkley.dice.rolling.KeepCount$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #35                 // Method "<init>":()V
       4: return
}


package com.newtranx.eval.utils

import kotlin.math.ln
import kotlin.math.min

/**
 * @Author: anson
 * @Date: 2022/1/29 11:41 PM
 */
inline fun <T> zip(vararg lists: List<T>): List<List<T>> {
    return zip(*lists, transform = { it })
}

inline fun <T, V> zip(vararg lists: List<T>, transform: (List<T>) -> V): List<V> {
    val minSize = lists.map(List<T>::size).minOrNull() ?: return emptyList()
    val list = ArrayList<V>(minSize)

    val iterators = lists.map { it.iterator() }
    var i = 0
    while (i < minSize) {
        list.add(transform(iterators.map { it.next() }))
        i++
    }
    return list
}

/**
 * Extracts all ngrams (min_order <= n <= max_order) from a sentence.
 * @param line: A string sentence.
 * @param minOrder: Minimum n-gram order.
 * @param maxOrder: Maximum n-gram order.
 * @return a Counter object with n-grams counts and the sequence length.
 */
fun extractAllWordNgrams(
    line: String,
    minOrder: Int,
    maxOrder: Int
): Pair<Counter<List<String>>, Double> {
    val counter = Counter<List<String>>()
    val tokens = line.split(" ")
    (minOrder until maxOrder + 1).forEach { n ->
        val nGrams = extractNgrams(tokens, n)
        counter.update(nGrams)
    }
    return Pair(counter, tokens.size.toDouble())
}

fun extractNgrams(
    tokens: List<String>,
    n: Int = 1
): List<List<String>> {
    return (0 until (tokens.size - n + 1)).map { i ->
        tokens.subList(i, i + n)
    }
}

class Counter<T>(
    data: List<T>? = null
) {
    private val store = mutableMapOf<T, Int>()
    private val keys = mutableSetOf<T>()

    init {
        if (data != null)
            this.update(data)
    }

    fun update(data: List<T>) {
        data.forEach { key ->
            val count = store[key] ?: 0
            if (count == 0) {
                keys.add(key)
            }
            store[key] = count + 1
        }
    }

    private fun add(key: T, count: Int) {
        store[key] = count
        keys.add(key)
    }

    fun keys(): Set<T> {
        return keys
    }

    fun values(): List<Int> {
        return store.values.toList()
    }

    fun count(key: T): Int {
        return store[key] ?: 0
    }

    fun exist(key: T): Boolean {
        return store.containsKey(key)
    }

    fun intersect(counter: Counter<T>): Counter<T> {
        val iKeys = this.keys intersect counter.keys
        val newCounter = Counter<T>()
        iKeys.forEach {
            val cur = count(it)
            val income = counter.count(it)
            val value = min(cur, income)
            newCounter.add(it, value)
        }
        return newCounter
    }

    operator fun set(key: T, count: Int) {
        if (!store.containsKey(key)) {
            keys.add(key)
        }
        store[key] = 0.takeIf { count < 0 } ?: count
    }

}

inline fun <T, V> Counter<T>.map(transform: (key: T, count: Int) -> V): List<V> {
    val array = mutableListOf<V>()
    this.keys().forEach {
        val item = transform.invoke(it, this.count(it))
        array.add(item)
    }
    return array
}

inline fun <T> Counter<T>.forEach(action: (key: T, count: Int) -> Unit) {
    this.keys().forEach {
        action.invoke(it, this.count(it))
    }
}

/**
 * Floors the log function
 * @param num: the number
 * @return log(num) floored to a very low number
 */
fun myLog(num: Double): Double {
    if (num == 0.0)
        return -9999999999.0
    return ln(num)
}

/**
 * Aggregates list of numeric lists by summing.
 */
fun sumOfLists(lists: List<List<Double>>): List<Double> {
    // Aggregates list of numeric lists by summing.
    if (lists.size == 1) {
        return lists[0]
    }

    // Preserve datatype
    val size = lists[0].size
    val total = DoubleArray(size) { 0.0 }
    lists.forEach { ll ->
        (0 until size).forEach { i ->
            total[i] = total[i].plus(ll[i])
        }
    }
    return total.toList()
}

Compiled from "func.kt"
public final class com.newtranx.eval.utils.FuncKt {
  public static final <T> java.util.List<java.util.List<T>> zip(java.util.List<? extends T>...);
    Code:
       0: aload_0
       1: ldc           #10                 // String lists
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: aload_0
      10: arraylength
      11: invokestatic  #22                 // Method java/util/Arrays.copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;
      14: checkcast     #24                 // class "[Ljava/util/List;"
      17: astore_2
      18: iconst_0
      19: istore_3
      20: aload_2
      21: astore        4
      23: iconst_0
      24: istore        5
      26: aload         4
      28: astore        6
      30: new           #26                 // class java/util/ArrayList
      33: dup
      34: aload         4
      36: arraylength
      37: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      40: checkcast     #32                 // class java/util/Collection
      43: astore        7
      45: iconst_0
      46: istore        8
      48: iconst_0
      49: istore        9
      51: aload         6
      53: arraylength
      54: istore        10
      56: iload         9
      58: iload         10
      60: if_icmpge     106
      63: aload         6
      65: iload         9
      67: aaload
      68: astore        11
      70: aload         7
      72: aload         11
      74: astore        12
      76: astore        13
      78: iconst_0
      79: istore        14
      81: aload         12
      83: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
      88: invokestatic  #44                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: aload         13
      93: swap
      94: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      99: pop
     100: iinc          9, 1
     103: goto          56
     106: aload         7
     108: checkcast     #34                 // class java/util/List
     111: nop
     112: checkcast     #50                 // class java/lang/Iterable
     115: invokestatic  #56                 // Method kotlin/collections/CollectionsKt.minOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     118: checkcast     #40                 // class java/lang/Integer
     121: dup
     122: ifnull        131
     125: invokevirtual #59                 // Method java/lang/Integer.intValue:()I
     128: goto          138
     131: pop
     132: invokestatic  #63                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     135: goto          389
     138: istore        15
     140: new           #26                 // class java/util/ArrayList
     143: dup
     144: iload         15
     146: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     149: astore        16
     151: aload_2
     152: astore        5
     154: iconst_0
     155: istore        6
     157: aload         5
     159: astore        7
     161: new           #26                 // class java/util/ArrayList
     164: dup
     165: aload         5
     167: arraylength
     168: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     171: checkcast     #32                 // class java/util/Collection
     174: astore        8
     176: iconst_0
     177: istore        9
     179: iconst_0
     180: istore        10
     182: aload         7
     184: arraylength
     185: istore        11
     187: iload         10
     189: iload         11
     191: if_icmpge     234
     194: aload         7
     196: iload         10
     198: aaload
     199: astore        12
     201: aload         8
     203: aload         12
     205: astore        14
     207: astore        13
     209: iconst_0
     210: istore        17
     212: aload         14
     214: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     219: aload         13
     221: swap
     222: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     227: pop
     228: iinc          10, 1
     231: goto          187
     234: aload         8
     236: checkcast     #34                 // class java/util/List
     239: nop
     240: astore        4
     242: iconst_0
     243: istore        5
     245: iload         5
     247: iload         15
     249: if_icmpge     384
     252: aload         16
     254: aload         4
     256: checkcast     #50                 // class java/lang/Iterable
     259: astore        6
     261: astore        13
     263: iconst_0
     264: istore        7
     266: aload         6
     268: astore        8
     270: new           #26                 // class java/util/ArrayList
     273: dup
     274: aload         6
     276: bipush        10
     278: invokestatic  #71                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     281: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     284: checkcast     #32                 // class java/util/Collection
     287: astore        9
     289: iconst_0
     290: istore        10
     292: aload         8
     294: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     299: astore        11
     301: aload         11
     303: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     308: ifeq          353
     311: aload         11
     313: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     318: astore        12
     320: aload         9
     322: aload         12
     324: checkcast     #74                 // class java/util/Iterator
     327: astore        14
     329: astore        18
     331: iconst_0
     332: istore        17
     334: aload         14
     336: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     341: aload         18
     343: swap
     344: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     349: pop
     350: goto          301
     353: aload         9
     355: checkcast     #34                 // class java/util/List
     358: nop
     359: aload         13
     361: swap
     362: astore        19
     364: astore        21
     366: iconst_0
     367: istore        20
     369: aload         19
     371: aload         21
     373: swap
     374: invokevirtual #83                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     377: pop
     378: iinc          5, 1
     381: goto          245
     384: aload         16
     386: checkcast     #34                 // class java/util/List
     389: areturn

  public static final <T, V> java.util.List<V> zip(java.util.List<? extends T>[], kotlin.jvm.functions.Function1<? super java.util.List<? extends T>, ? extends V>);
    Code:
       0: aload_0
       1: ldc           #10                 // String lists
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #114                // String transform
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: aload_0
      15: astore        5
      17: iconst_0
      18: istore        6
      20: aload         5
      22: astore        7
      24: new           #26                 // class java/util/ArrayList
      27: dup
      28: aload         5
      30: arraylength
      31: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      34: checkcast     #32                 // class java/util/Collection
      37: astore        8
      39: iconst_0
      40: istore        9
      42: iconst_0
      43: istore        10
      45: aload         7
      47: arraylength
      48: istore        11
      50: iload         10
      52: iload         11
      54: if_icmpge     100
      57: aload         7
      59: iload         10
      61: aaload
      62: astore        12
      64: aload         8
      66: aload         12
      68: astore        13
      70: astore        16
      72: iconst_0
      73: istore        14
      75: aload         13
      77: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
      82: invokestatic  #44                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: aload         16
      87: swap
      88: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: iinc          10, 1
      97: goto          50
     100: aload         8
     102: checkcast     #34                 // class java/util/List
     105: nop
     106: checkcast     #50                 // class java/lang/Iterable
     109: invokestatic  #56                 // Method kotlin/collections/CollectionsKt.minOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     112: checkcast     #40                 // class java/lang/Integer
     115: dup
     116: ifnull        125
     119: invokevirtual #59                 // Method java/lang/Integer.intValue:()I
     122: goto          130
     125: pop
     126: invokestatic  #63                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     129: areturn
     130: istore_3
     131: new           #26                 // class java/util/ArrayList
     134: dup
     135: iload_3
     136: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     139: astore        4
     141: aload_0
     142: astore        6
     144: iconst_0
     145: istore        7
     147: aload         6
     149: astore        8
     151: new           #26                 // class java/util/ArrayList
     154: dup
     155: aload         6
     157: arraylength
     158: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     161: checkcast     #32                 // class java/util/Collection
     164: astore        9
     166: iconst_0
     167: istore        10
     169: iconst_0
     170: istore        11
     172: aload         8
     174: arraylength
     175: istore        12
     177: iload         11
     179: iload         12
     181: if_icmpge     224
     184: aload         8
     186: iload         11
     188: aaload
     189: astore        13
     191: aload         9
     193: aload         13
     195: astore        14
     197: astore        16
     199: iconst_0
     200: istore        15
     202: aload         14
     204: invokeinterface #67,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     209: aload         16
     211: swap
     212: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     217: pop
     218: iinc          11, 1
     221: goto          177
     224: aload         9
     226: checkcast     #34                 // class java/util/List
     229: nop
     230: astore        5
     232: iconst_0
     233: istore        6
     235: iload         6
     237: iload_3
     238: if_icmpge     374
     241: aload         4
     243: aload_1
     244: aload         5
     246: checkcast     #50                 // class java/lang/Iterable
     249: astore        7
     251: astore        17
     253: astore        16
     255: iconst_0
     256: istore        8
     258: aload         7
     260: astore        9
     262: new           #26                 // class java/util/ArrayList
     265: dup
     266: aload         7
     268: bipush        10
     270: invokestatic  #71                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     273: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     276: checkcast     #32                 // class java/util/Collection
     279: astore        10
     281: iconst_0
     282: istore        11
     284: aload         9
     286: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     291: astore        12
     293: aload         12
     295: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     300: ifeq          345
     303: aload         12
     305: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     310: astore        13
     312: aload         10
     314: aload         13
     316: checkcast     #74                 // class java/util/Iterator
     319: astore        14
     321: astore        18
     323: iconst_0
     324: istore        15
     326: aload         14
     328: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     333: aload         18
     335: swap
     336: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     341: pop
     342: goto          293
     345: aload         10
     347: checkcast     #34                 // class java/util/List
     350: nop
     351: astore        18
     353: aload         16
     355: aload         17
     357: aload         18
     359: invokeinterface #120,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     364: invokevirtual #83                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     367: pop
     368: iinc          6, 1
     371: goto          235
     374: aload         4
     376: checkcast     #34                 // class java/util/List
     379: areturn

  public static final kotlin.Pair<com.newtranx.eval.utils.Counter<java.util.List<java.lang.String>>, java.lang.Double> extractAllWordNgrams(java.lang.String, int, int);
    Code:
       0: aload_0
       1: ldc           #138                // String line
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #140                // class com/newtranx/eval/utils/Counter
       9: dup
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokespecial #143                // Method com/newtranx/eval/utils/Counter."<init>":(Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      16: astore_3
      17: aload_0
      18: checkcast     #145                // class java/lang/CharSequence
      21: iconst_1
      22: anewarray     #147                // class java/lang/String
      25: astore        5
      27: aload         5
      29: iconst_0
      30: ldc           #149                // String
      32: aastore
      33: aload         5
      35: iconst_0
      36: iconst_0
      37: bipush        6
      39: aconst_null
      40: invokestatic  #155                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      43: astore        4
      45: iload_1
      46: iload_2
      47: iconst_1
      48: iadd
      49: invokestatic  #161                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      52: checkcast     #50                 // class java/lang/Iterable
      55: astore        5
      57: iconst_0
      58: istore        6
      60: aload         5
      62: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      67: astore        7
      69: aload         7
      71: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          116
      79: aload         7
      81: checkcast     #163                // class kotlin/collections/IntIterator
      84: invokevirtual #166                // Method kotlin/collections/IntIterator.nextInt:()I
      87: istore        8
      89: iload         8
      91: istore        9
      93: iconst_0
      94: istore        10
      96: aload         4
      98: iload         9
     100: invokestatic  #170                // Method extractNgrams:(Ljava/util/List;I)Ljava/util/List;
     103: astore        11
     105: aload_3
     106: aload         11
     108: invokevirtual #174                // Method com/newtranx/eval/utils/Counter.update:(Ljava/util/List;)V
     111: nop
     112: nop
     113: goto          69
     116: nop
     117: new           #176                // class kotlin/Pair
     120: dup
     121: aload_3
     122: aload         4
     124: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
     129: i2d
     130: invokestatic  #181                // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     133: invokespecial #184                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     136: areturn

  public static final java.util.List<java.util.List<java.lang.String>> extractNgrams(java.util.List<java.lang.String>, int);
    Code:
       0: aload_0
       1: ldc           #198                // String tokens
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: aload_0
       8: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
      13: iload_1
      14: isub
      15: iconst_1
      16: iadd
      17: invokestatic  #161                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      20: checkcast     #50                 // class java/lang/Iterable
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: astore        4
      29: new           #26                 // class java/util/ArrayList
      32: dup
      33: aload_2
      34: bipush        10
      36: invokestatic  #71                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      39: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      42: checkcast     #32                 // class java/util/Collection
      45: astore        5
      47: iconst_0
      48: istore        6
      50: aload         4
      52: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        7
      59: aload         7
      61: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          114
      69: aload         7
      71: checkcast     #163                // class kotlin/collections/IntIterator
      74: invokevirtual #166                // Method kotlin/collections/IntIterator.nextInt:()I
      77: istore        8
      79: aload         5
      81: iload         8
      83: istore        9
      85: astore        11
      87: iconst_0
      88: istore        10
      90: aload_0
      91: iload         9
      93: iload         9
      95: iload_1
      96: iadd
      97: invokeinterface #202,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     102: aload         11
     104: swap
     105: invokeinterface #48,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     110: pop
     111: goto          59
     114: aload         5
     116: checkcast     #34                 // class java/util/List
     119: nop
     120: areturn

  public static java.util.List extractNgrams$default(java.util.List, int, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_1
       7: istore_1
       8: aload_0
       9: iload_1
      10: invokestatic  #170                // Method extractNgrams:(Ljava/util/List;I)Ljava/util/List;
      13: areturn

  public static final <T, V> java.util.List<V> map(com.newtranx.eval.utils.Counter<T>, kotlin.jvm.functions.Function2<? super T, ? super java.lang.Integer, ? extends V>);
    Code:
       0: aload_0
       1: ldc           #210                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #114                // String transform
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: new           #26                 // class java/util/ArrayList
      17: dup
      18: invokespecial #213                // Method java/util/ArrayList."<init>":()V
      21: checkcast     #34                 // class java/util/List
      24: astore_3
      25: aload_0
      26: invokevirtual #217                // Method com/newtranx/eval/utils/Counter.keys:()Ljava/util/Set;
      29: checkcast     #50                 // class java/lang/Iterable
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload         4
      39: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        6
      46: aload         6
      48: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          105
      56: aload         6
      58: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        7
      65: aload         7
      67: astore        8
      69: iconst_0
      70: istore        9
      72: aload_1
      73: aload         8
      75: aload_0
      76: aload         8
      78: invokevirtual #221                // Method com/newtranx/eval/utils/Counter.count:(Ljava/lang/Object;)I
      81: invokestatic  #44                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      84: invokeinterface #226,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      89: astore        10
      91: aload_3
      92: aload         10
      94: invokeinterface #227,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      99: pop
     100: nop
     101: nop
     102: goto          46
     105: nop
     106: aload_3
     107: areturn

  public static final <T> void forEach(com.newtranx.eval.utils.Counter<T>, kotlin.jvm.functions.Function2<? super T, ? super java.lang.Integer, kotlin.Unit>);
    Code:
       0: aload_0
       1: ldc           #210                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #237                // String action
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: aload_0
      15: invokevirtual #217                // Method com/newtranx/eval/utils/Counter.keys:()Ljava/util/Set;
      18: checkcast     #50                 // class java/lang/Iterable
      21: astore_3
      22: iconst_0
      23: istore        4
      25: aload_3
      26: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      31: astore        5
      33: aload         5
      35: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          82
      43: aload         5
      45: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: astore        6
      52: aload         6
      54: astore        7
      56: iconst_0
      57: istore        8
      59: aload_1
      60: aload         7
      62: aload_0
      63: aload         7
      65: invokevirtual #221                // Method com/newtranx/eval/utils/Counter.count:(Ljava/lang/Object;)I
      68: invokestatic  #44                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: invokeinterface #226,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      76: pop
      77: nop
      78: nop
      79: goto          33
      82: nop
      83: return

  public static final double myLog(double);
    Code:
       0: dload_0
       1: dconst_0
       2: dcmpg
       3: ifne          10
       6: iconst_1
       7: goto          11
      10: iconst_0
      11: ifeq          18
      14: ldc2_w        #242                // double -9.999999999E9d
      17: dreturn
      18: dload_0
      19: invokestatic  #248                // Method java/lang/Math.log:(D)D
      22: dreturn

  public static final java.util.List<java.lang.Double> sumOfLists(java.util.List<? extends java.util.List<java.lang.Double>>);
    Code:
       0: aload_0
       1: ldc           #10                 // String lists
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
      12: iconst_1
      13: if_icmpne     27
      16: aload_0
      17: iconst_0
      18: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      23: checkcast     #34                 // class java/util/List
      26: areturn
      27: aload_0
      28: iconst_0
      29: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #34                 // class java/util/List
      37: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
      42: istore_1
      43: iconst_0
      44: istore_3
      45: iload_1
      46: newarray       double
      48: astore        4
      50: iload_3
      51: iload_1
      52: if_icmpge     70
      55: iload_3
      56: istore        5
      58: aload         4
      60: iload         5
      62: dconst_0
      63: dastore
      64: iinc          3, 1
      67: goto          50
      70: aload         4
      72: astore_2
      73: aload_0
      74: checkcast     #50                 // class java/lang/Iterable
      77: astore_3
      78: iconst_0
      79: istore        4
      81: aload_3
      82: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        5
      89: aload         5
      91: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          202
      99: aload         5
     101: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: astore        6
     108: aload         6
     110: checkcast     #34                 // class java/util/List
     113: astore        7
     115: iconst_0
     116: istore        8
     118: iconst_0
     119: iload_1
     120: invokestatic  #161                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     123: checkcast     #50                 // class java/lang/Iterable
     126: astore        9
     128: iconst_0
     129: istore        10
     131: aload         9
     133: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     138: astore        11
     140: aload         11
     142: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     147: ifeq          196
     150: aload         11
     152: checkcast     #163                // class kotlin/collections/IntIterator
     155: invokevirtual #166                // Method kotlin/collections/IntIterator.nextInt:()I
     158: istore        12
     160: iload         12
     162: istore        13
     164: iconst_0
     165: istore        14
     167: aload_2
     168: iload         13
     170: aload_2
     171: iload         13
     173: daload
     174: aload         7
     176: iload         13
     178: invokeinterface #257,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     183: checkcast     #259                // class java/lang/Number
     186: invokevirtual #263                // Method java/lang/Number.doubleValue:()D
     189: dadd
     190: dastore
     191: nop
     192: nop
     193: goto          140
     196: nop
     197: nop
     198: nop
     199: goto          89
     202: nop
     203: aload_2
     204: invokestatic  #269                // Method kotlin/collections/ArraysKt.toList:([D)Ljava/util/List;
     207: areturn
}


package dev.vengateshm.kotlin_practice.programs

fun main() {
//    println(findAnagramsPatternsStartIndicesInString("", "abc").toString())
//    println(findAnagramsPatternsStartIndicesInString("abc", "abca").toString())
    println(findAnagramsPatternsStartIndicesInString("abczzbcabcadeb", "abc").toString())
//    println(findAnagramsPatternsStartIndicesInString("abacab", "ab").toString())
}

fun findAnagramsPatternsStartIndicesInString(str: String, pattern: String): List<Int>? {
    // Handle corner cases
    if (isInvalid(str, pattern)) {
        println("Invalid string or pattern")
        return null
    }
    if (pattern.length > str.length) {
        println("Pattern is larger than string")
        return null
    }
    val windowSize = pattern.length
    val strLength = str.length
    val patternCharCountMap = mutableMapOf<Char, Int>()
    val stringCharCountMap = mutableMapOf<Char, Int>()
    val indices = mutableListOf<Int>()

    // Generate count map for first window in str and pattern
    for (i in 0 until windowSize) {
        generateWindowCharCountMap(pattern[i], patternCharCountMap)
        generateWindowCharCountMap(str[i], stringCharCountMap)
    }

    // Start at the end of the first window
    for (windowRightBound in windowSize until strLength) {
        if (compareMap(patternCharCountMap, stringCharCountMap)) {
            indices.add(windowRightBound - windowSize)
        }

        // Remove first character in the window
        val oldCharIndex = windowRightBound - windowSize
        val oldChar = str[oldCharIndex]
        var oldCharCount = stringCharCountMap[oldChar]!!
        if (oldCharCount == 1) {
            stringCharCountMap.remove(oldChar)
        } else {
            oldCharCount--
            stringCharCountMap[oldChar] = oldCharCount
        }

        // Add the new char to the window
        generateWindowCharCountMap(str[windowRightBound], stringCharCountMap)
    }

    // At this point last window comparison remains
    // so compare one last time
    if (compareMap(patternCharCountMap, stringCharCountMap)) {
        indices.add(strLength - windowSize)
    }

    return indices
}

fun generateWindowCharCountMap(char: Char, map: MutableMap<Char, Int>) {
    var count = map[char]
    if (count == null) {
        count = 0;
    }
    count++
    map[char] = count
}

fun isInvalid(str: String?, pattern: String?): Boolean {
    return str.isNullOrEmpty() || pattern.isNullOrEmpty()
}

fun compareMap(patternMap: Map<Char, Int>, strMap: Map<Char, Int>): Boolean {
    for (entry in patternMap) {
        val char = entry.key
        val count = entry.value
        if (strMap[char] == null || strMap[char] != count) {
            return false
        }
    }
    return true
}

Compiled from "AnagramSubStringSearchHashMapImpl.kt"
public final class dev.vengateshm.kotlin_practice.programs.AnagramSubStringSearchHashMapImplKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String abczzbcabcadeb
       2: ldc           #10                 // String abc
       4: invokestatic  #14                 // Method findAnagramsPatternsStartIndicesInString:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
       7: invokestatic  #20                 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
      10: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
      13: swap
      14: invokevirtual #32                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      17: return

  public static final java.util.List<java.lang.Integer> findAnagramsPatternsStartIndicesInString(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #37                 // String str
       3: invokestatic  #43                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #45                 // String pattern
       9: invokestatic  #43                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #49                 // Method isInvalid:(Ljava/lang/String;Ljava/lang/String;)Z
      17: ifeq          31
      20: ldc           #51                 // String Invalid string or pattern
      22: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
      25: swap
      26: invokevirtual #32                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      29: aconst_null
      30: areturn
      31: aload_1
      32: invokevirtual #55                 // Method java/lang/String.length:()I
      35: aload_0
      36: invokevirtual #55                 // Method java/lang/String.length:()I
      39: if_icmple     53
      42: ldc           #57                 // String Pattern is larger than string
      44: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
      47: swap
      48: invokevirtual #32                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      51: aconst_null
      52: areturn
      53: aload_1
      54: invokevirtual #55                 // Method java/lang/String.length:()I
      57: istore_2
      58: aload_0
      59: invokevirtual #55                 // Method java/lang/String.length:()I
      62: istore_3
      63: new           #59                 // class java/util/LinkedHashMap
      66: dup
      67: invokespecial #62                 // Method java/util/LinkedHashMap."<init>":()V
      70: checkcast     #64                 // class java/util/Map
      73: astore        4
      75: new           #59                 // class java/util/LinkedHashMap
      78: dup
      79: invokespecial #62                 // Method java/util/LinkedHashMap."<init>":()V
      82: checkcast     #64                 // class java/util/Map
      85: astore        5
      87: new           #66                 // class java/util/ArrayList
      90: dup
      91: invokespecial #67                 // Method java/util/ArrayList."<init>":()V
      94: checkcast     #69                 // class java/util/List
      97: astore        6
      99: iconst_0
     100: istore        7
     102: iload         7
     104: iload_2
     105: if_icmpge     136
     108: aload_1
     109: iload         7
     111: invokevirtual #73                 // Method java/lang/String.charAt:(I)C
     114: aload         4
     116: invokestatic  #77                 // Method generateWindowCharCountMap:(CLjava/util/Map;)V
     119: aload_0
     120: iload         7
     122: invokevirtual #73                 // Method java/lang/String.charAt:(I)C
     125: aload         5
     127: invokestatic  #77                 // Method generateWindowCharCountMap:(CLjava/util/Map;)V
     130: iinc          7, 1
     133: goto          102
     136: iload_2
     137: istore        7
     139: iload         7
     141: iload_3
     142: if_icmpge     276
     145: aload         4
     147: aload         5
     149: invokestatic  #81                 // Method compareMap:(Ljava/util/Map;Ljava/util/Map;)Z
     152: ifeq          170
     155: aload         6
     157: iload         7
     159: iload_2
     160: isub
     161: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     164: invokeinterface #90,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     169: pop
     170: iload         7
     172: iload_2
     173: isub
     174: istore        8
     176: aload_0
     177: iload         8
     179: invokevirtual #73                 // Method java/lang/String.charAt:(I)C
     182: istore        9
     184: aload         5
     186: iload         9
     188: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     191: invokeinterface #99,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     196: dup
     197: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     200: checkcast     #104                // class java/lang/Number
     203: invokevirtual #107                // Method java/lang/Number.intValue:()I
     206: istore        10
     208: iload         10
     210: iconst_1
     211: if_icmpne     230
     214: aload         5
     216: iload         9
     218: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     221: invokeinterface #110,  2          // InterfaceMethod java/util/Map.remove:(Ljava/lang/Object;)Ljava/lang/Object;
     226: pop
     227: goto          259
     230: iinc          10, -1
     233: iload         9
     235: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     238: astore        11
     240: iload         10
     242: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: astore        12
     247: aload         5
     249: aload         11
     251: aload         12
     253: invokeinterface #114,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     258: pop
     259: aload_0
     260: iload         7
     262: invokevirtual #73                 // Method java/lang/String.charAt:(I)C
     265: aload         5
     267: invokestatic  #77                 // Method generateWindowCharCountMap:(CLjava/util/Map;)V
     270: iinc          7, 1
     273: goto          139
     276: aload         4
     278: aload         5
     280: invokestatic  #81                 // Method compareMap:(Ljava/util/Map;Ljava/util/Map;)Z
     283: ifeq          300
     286: aload         6
     288: iload_3
     289: iload_2
     290: isub
     291: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     294: invokeinterface #90,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     299: pop
     300: aload         6
     302: areturn

  public static final void generateWindowCharCountMap(char, java.util.Map<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #132                // String map
       3: invokestatic  #43                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: iload_0
       8: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      11: invokeinterface #99,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      16: checkcast     #83                 // class java/lang/Integer
      19: astore_2
      20: aload_2
      21: ifnonnull     29
      24: iconst_0
      25: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: astore_2
      29: aload_2
      30: invokevirtual #133                // Method java/lang/Integer.intValue:()I
      33: istore_3
      34: iload_3
      35: iconst_1
      36: iadd
      37: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: astore_2
      41: iload_0
      42: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      45: astore        4
      47: aload_1
      48: aload         4
      50: aload_2
      51: invokeinterface #114,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      56: pop
      57: return

  public static final boolean isInvalid(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #138                // class java/lang/CharSequence
       4: astore_2
       5: aload_2
       6: ifnull        18
       9: aload_2
      10: invokeinterface #139,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      15: ifne          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifne          52
      26: aload_1
      27: checkcast     #138                // class java/lang/CharSequence
      30: astore_2
      31: aload_2
      32: ifnull        44
      35: aload_2
      36: invokeinterface #139,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      41: ifne          48
      44: iconst_1
      45: goto          49
      48: iconst_0
      49: ifeq          56
      52: iconst_1
      53: goto          57
      56: iconst_0
      57: ireturn

  public static final boolean compareMap(java.util.Map<java.lang.Character, java.lang.Integer>, java.util.Map<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #142                // String patternMap
       3: invokestatic  #43                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #144                // String strMap
       9: invokestatic  #43                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #148,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      18: invokeinterface #154,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      23: astore_2
      24: aload_2
      25: invokeinterface #160,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          121
      33: aload_2
      34: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #166                // class java/util/Map$Entry
      42: astore_3
      43: aload_3
      44: invokeinterface #169,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      49: checkcast     #92                 // class java/lang/Character
      52: invokevirtual #173                // Method java/lang/Character.charValue:()C
      55: istore        4
      57: aload_3
      58: invokeinterface #176,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      63: checkcast     #104                // class java/lang/Number
      66: invokevirtual #107                // Method java/lang/Number.intValue:()I
      69: istore        5
      71: aload_1
      72: iload         4
      74: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      77: invokeinterface #99,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      82: ifnull        119
      85: aload_1
      86: iload         4
      88: invokestatic  #95                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      91: invokeinterface #99,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      96: checkcast     #83                 // class java/lang/Integer
      99: iload         5
     101: istore        6
     103: dup
     104: ifnonnull     111
     107: pop
     108: goto          119
     111: invokevirtual #133                // Method java/lang/Integer.intValue:()I
     114: iload         6
     116: if_icmpeq     24
     119: iconst_0
     120: ireturn
     121: iconst_1
     122: ireturn

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


package com.yp.day9

import java.io.File
import kotlin.math.abs

class AOC9 {

    fun process() {
        val input =  File("/home/ben/aoc/input-9.txt")

        val instructions =  input.useLines { it.toList() }

        val p1 = (0..1).map { Pair(0, 0) }.toMutableList()
        val p2 = (0..9).map { Pair(0, 0) }.toMutableList()

        println("Part1: ${scan(p1, instructions)}")
        println("Part2: ${scan(p2, instructions)}")

    }

    private fun scan(rope: MutableList<Pair<Int, Int>>, input: List<String>): Int {
        val visitedPositions = mutableSetOf<Pair<Int, Int>>()
        visitedPositions.add(rope.last())
        input.forEach { instruction ->
            val cmd = instruction.split(" ")
            (1..cmd[1].toInt()).forEach { _ ->
                rope[0] = processStep(cmd[0], rope[0])
                (0 until rope.size - 1).forEachIndexed { index, _ ->
                    val newPositions =
                        tail(rope[index], rope[index + 1])

                    rope[index + 1] = newPositions
                }
                visitedPositions.add(rope.last())
            }
        }
        return visitedPositions.size
    }

    private fun tail(
        headPosition: Pair<Int, Int>,
        tailPosition: Pair<Int, Int>
    ): Pair<Int, Int> {
        return when {
            abs((headPosition.first - tailPosition.first)) > 1 || abs((headPosition.second - tailPosition.second)) > 1 -> {
                when {
                    headPosition.first == tailPosition.first -> {
                        Pair(
                            tailPosition.first,
                            if (headPosition.second > tailPosition.second) tailPosition.second + 1 else tailPosition.second - 1
                        )
                    }
                    headPosition.second == tailPosition.second -> {
                        Pair(
                            if (headPosition.first > tailPosition.first) tailPosition.first + 1 else tailPosition.first - 1,
                            tailPosition.second
                        )
                    }
                    else -> {
                        val xDiff = (headPosition.first - tailPosition.first)
                        val yDiff = (headPosition.second - tailPosition.second)
                        val changeX = abs(xDiff) > 1 || (abs(xDiff) > 0 && abs(yDiff) > 1)
                        val changeY = abs(yDiff) > 1 || (abs(yDiff) > 0 && abs(xDiff) > 1)
                        Pair(
                            if (changeX) tailPosition.first + (if (xDiff < 0) -1 else 1) else tailPosition.first,
                            if (changeY) tailPosition.second + (if (yDiff < 0) -1 else 1) else tailPosition.second,
                        )
                    }
                }
            }
            else -> tailPosition
        }
    }

    private fun processStep(step: String, headPosition: Pair<Int, Int>): Pair<Int, Int> {
        val (x, y) = headPosition
        return when (step) {
            "U" -> headPosition.copy(second = y - 1)
            "D" -> headPosition.copy(second = y + 1)
            "L" -> headPosition.copy(first = x - 1)
            "R" -> headPosition.copy(first = x + 1)
            else -> { throw IllegalStateException() }
        }
    }
}

Compiled from "AOC9.kt"
public final class com.yp.day9.AOC9 {
  public com.yp.day9.AOC9();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void process();
    Code:
       0: new           #15                 // class java/io/File
       3: dup
       4: ldc           #17                 // String /home/ben/aoc/input-9.txt
       6: invokespecial #20                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: aload_1
      11: astore_3
      12: getstatic     #26                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      15: astore        4
      17: iconst_0
      18: istore        5
      20: aload_3
      21: astore        6
      23: sipush        8192
      26: istore        7
      28: aload         6
      30: astore        8
      32: new           #28                 // class java/io/InputStreamReader
      35: dup
      36: new           #30                 // class java/io/FileInputStream
      39: dup
      40: aload         8
      42: invokespecial #33                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      45: checkcast     #35                 // class java/io/InputStream
      48: aload         4
      50: invokespecial #38                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      53: checkcast     #40                 // class java/io/Reader
      56: astore        8
      58: aload         8
      60: instanceof    #42                 // class java/io/BufferedReader
      63: ifeq          74
      66: aload         8
      68: checkcast     #42                 // class java/io/BufferedReader
      71: goto          85
      74: new           #42                 // class java/io/BufferedReader
      77: dup
      78: aload         8
      80: iload         7
      82: invokespecial #45                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      85: checkcast     #47                 // class java/io/Closeable
      88: astore        6
      90: aconst_null
      91: astore        7
      93: nop
      94: aload         6
      96: checkcast     #42                 // class java/io/BufferedReader
      99: astore        8
     101: iconst_0
     102: istore        9
     104: aload         8
     106: invokestatic  #53                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     109: astore        10
     111: iconst_0
     112: istore        11
     114: aload         10
     116: invokestatic  #59                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     119: astore        8
     121: aload         6
     123: aload         7
     125: invokestatic  #65                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     128: aload         8
     130: goto          154
     133: astore        9
     135: aload         9
     137: astore        7
     139: aload         9
     141: athrow
     142: astore        9
     144: aload         6
     146: aload         7
     148: invokestatic  #65                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     151: aload         9
     153: athrow
     154: nop
     155: astore_2
     156: new           #67                 // class kotlin/ranges/IntRange
     159: dup
     160: iconst_0
     161: iconst_1
     162: invokespecial #70                 // Method kotlin/ranges/IntRange."<init>":(II)V
     165: checkcast     #72                 // class java/lang/Iterable
     168: astore        4
     170: iconst_0
     171: istore        5
     173: aload         4
     175: astore        6
     177: new           #74                 // class java/util/ArrayList
     180: dup
     181: aload         4
     183: bipush        10
     185: invokestatic  #80                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     188: invokespecial #83                 // Method java/util/ArrayList."<init>":(I)V
     191: checkcast     #85                 // class java/util/Collection
     194: astore        7
     196: iconst_0
     197: istore        8
     199: aload         6
     201: invokeinterface #89,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     206: astore        9
     208: aload         9
     210: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     215: ifeq          266
     218: aload         9
     220: checkcast     #97                 // class kotlin/collections/IntIterator
     223: invokevirtual #101                // Method kotlin/collections/IntIterator.nextInt:()I
     226: istore        10
     228: aload         7
     230: iload         10
     232: istore        11
     234: astore        14
     236: iconst_0
     237: istore        12
     239: new           #103                // class kotlin/Pair
     242: dup
     243: iconst_0
     244: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     247: iconst_0
     248: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     251: invokespecial #112                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     254: aload         14
     256: swap
     257: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     262: pop
     263: goto          208
     266: aload         7
     268: checkcast     #118                // class java/util/List
     271: nop
     272: checkcast     #85                 // class java/util/Collection
     275: invokestatic  #122                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     278: astore_3
     279: new           #67                 // class kotlin/ranges/IntRange
     282: dup
     283: iconst_0
     284: bipush        9
     286: invokespecial #70                 // Method kotlin/ranges/IntRange."<init>":(II)V
     289: checkcast     #72                 // class java/lang/Iterable
     292: astore        5
     294: iconst_0
     295: istore        6
     297: aload         5
     299: astore        7
     301: new           #74                 // class java/util/ArrayList
     304: dup
     305: aload         5
     307: bipush        10
     309: invokestatic  #80                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     312: invokespecial #83                 // Method java/util/ArrayList."<init>":(I)V
     315: checkcast     #85                 // class java/util/Collection
     318: astore        8
     320: iconst_0
     321: istore        9
     323: aload         7
     325: invokeinterface #89,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     330: astore        10
     332: aload         10
     334: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     339: ifeq          390
     342: aload         10
     344: checkcast     #97                 // class kotlin/collections/IntIterator
     347: invokevirtual #101                // Method kotlin/collections/IntIterator.nextInt:()I
     350: istore        11
     352: aload         8
     354: iload         11
     356: istore        12
     358: astore        14
     360: iconst_0
     361: istore        13
     363: new           #103                // class kotlin/Pair
     366: dup
     367: iconst_0
     368: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     371: iconst_0
     372: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     375: invokespecial #112                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     378: aload         14
     380: swap
     381: invokeinterface #116,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     386: pop
     387: goto          332
     390: aload         8
     392: checkcast     #118                // class java/util/List
     395: nop
     396: checkcast     #85                 // class java/util/Collection
     399: invokestatic  #122                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     402: astore        4
     404: new           #124                // class java/lang/StringBuilder
     407: dup
     408: invokespecial #125                // Method java/lang/StringBuilder."<init>":()V
     411: ldc           #127                // String Part1:
     413: invokevirtual #131                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     416: aload_0
     417: aload_3
     418: aload_2
     419: invokespecial #135                // Method scan:(Ljava/util/List;Ljava/util/List;)I
     422: invokevirtual #138                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     425: invokevirtual #142                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     428: getstatic     #148                // Field java/lang/System.out:Ljava/io/PrintStream;
     431: swap
     432: invokevirtual #154                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     435: new           #124                // class java/lang/StringBuilder
     438: dup
     439: invokespecial #125                // Method java/lang/StringBuilder."<init>":()V
     442: ldc           #156                // String Part2:
     444: invokevirtual #131                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     447: aload_0
     448: aload         4
     450: aload_2
     451: invokespecial #135                // Method scan:(Ljava/util/List;Ljava/util/List;)I
     454: invokevirtual #138                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     457: invokevirtual #142                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     460: getstatic     #148                // Field java/lang/System.out:Ljava/io/PrintStream;
     463: swap
     464: invokevirtual #154                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     467: return
    Exception table:
       from    to  target type
          93   121   133   Class java/lang/Throwable
          93   121   142   any
         133   142   142   any
         142   144   142   any

  private final int scan(java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, java.util.List<java.lang.String>);
    Code:
       0: new           #189                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #190                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #192                // class java/util/Set
      10: astore_3
      11: aload_3
      12: aload_1
      13: invokestatic  #196                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      16: invokeinterface #197,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      21: pop
      22: aload_2
      23: checkcast     #72                 // class java/lang/Iterable
      26: astore        4
      28: iconst_0
      29: istore        5
      31: aload         4
      33: invokeinterface #89,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        6
      40: aload         6
      42: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          338
      50: aload         6
      52: invokeinterface #201,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        7
      59: aload         7
      61: checkcast     #203                // class java/lang/String
      64: astore        8
      66: iconst_0
      67: istore        9
      69: aload         8
      71: checkcast     #205                // class java/lang/CharSequence
      74: iconst_1
      75: anewarray     #203                // class java/lang/String
      78: astore        10
      80: aload         10
      82: iconst_0
      83: ldc           #207                // String
      85: aastore
      86: aload         10
      88: iconst_0
      89: iconst_0
      90: bipush        6
      92: aconst_null
      93: invokestatic  #213                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      96: astore        11
      98: new           #67                 // class kotlin/ranges/IntRange
     101: dup
     102: iconst_1
     103: aload         11
     105: iconst_1
     106: invokeinterface #217,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     111: checkcast     #203                // class java/lang/String
     114: invokestatic  #221                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     117: invokespecial #70                 // Method kotlin/ranges/IntRange."<init>":(II)V
     120: checkcast     #72                 // class java/lang/Iterable
     123: astore        10
     125: iconst_0
     126: istore        12
     128: aload         10
     130: invokeinterface #89,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        13
     137: aload         13
     139: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          332
     147: aload         13
     149: checkcast     #97                 // class kotlin/collections/IntIterator
     152: invokevirtual #101                // Method kotlin/collections/IntIterator.nextInt:()I
     155: istore        14
     157: iconst_0
     158: istore        15
     160: aload_1
     161: iconst_0
     162: aload_0
     163: aload         11
     165: iconst_0
     166: invokeinterface #217,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     171: checkcast     #203                // class java/lang/String
     174: aload_1
     175: iconst_0
     176: invokeinterface #217,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     181: checkcast     #103                // class kotlin/Pair
     184: invokespecial #225                // Method processStep:(Ljava/lang/String;Lkotlin/Pair;)Lkotlin/Pair;
     187: invokeinterface #229,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     192: pop
     193: iconst_0
     194: aload_1
     195: invokeinterface #232,  1          // InterfaceMethod java/util/List.size:()I
     200: iconst_1
     201: isub
     202: invokestatic  #238                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     205: checkcast     #72                 // class java/lang/Iterable
     208: astore        16
     210: iconst_0
     211: istore        17
     213: iconst_0
     214: istore        18
     216: aload         16
     218: invokeinterface #89,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     223: astore        19
     225: aload         19
     227: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     232: ifeq          315
     235: aload         19
     237: checkcast     #97                 // class kotlin/collections/IntIterator
     240: invokevirtual #101                // Method kotlin/collections/IntIterator.nextInt:()I
     243: istore        20
     245: iload         18
     247: iinc          18, 1
     250: istore        21
     252: iload         21
     254: ifge          260
     257: invokestatic  #241                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     260: iload         21
     262: istore        22
     264: iconst_0
     265: istore        23
     267: aload_0
     268: aload_1
     269: iload         22
     271: invokeinterface #217,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     276: checkcast     #103                // class kotlin/Pair
     279: aload_1
     280: iload         22
     282: iconst_1
     283: iadd
     284: invokeinterface #217,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     289: checkcast     #103                // class kotlin/Pair
     292: invokespecial #245                // Method tail:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
     295: astore        24
     297: aload_1
     298: iload         22
     300: iconst_1
     301: iadd
     302: aload         24
     304: invokeinterface #229,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     309: pop
     310: nop
     311: nop
     312: goto          225
     315: nop
     316: aload_3
     317: aload_1
     318: invokestatic  #196                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     321: invokeinterface #197,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     326: pop
     327: nop
     328: nop
     329: goto          137
     332: nop
     333: nop
     334: nop
     335: goto          40
     338: nop
     339: aload_3
     340: invokeinterface #246,  1          // InterfaceMethod java/util/Set.size:()I
     345: ireturn

  private final kotlin.Pair<java.lang.Integer, java.lang.Integer> tail(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: nop
       1: aload_1
       2: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #272                // class java/lang/Number
       8: invokevirtual #275                // Method java/lang/Number.intValue:()I
      11: aload_2
      12: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      15: checkcast     #272                // class java/lang/Number
      18: invokevirtual #275                // Method java/lang/Number.intValue:()I
      21: isub
      22: invokestatic  #281                // Method java/lang/Math.abs:(I)I
      25: iconst_1
      26: if_icmpgt     57
      29: aload_1
      30: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      33: checkcast     #272                // class java/lang/Number
      36: invokevirtual #275                // Method java/lang/Number.intValue:()I
      39: aload_2
      40: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      43: checkcast     #272                // class java/lang/Number
      46: invokevirtual #275                // Method java/lang/Number.intValue:()I
      49: isub
      50: invokestatic  #281                // Method java/lang/Math.abs:(I)I
      53: iconst_1
      54: if_icmple     439
      57: nop
      58: aload_1
      59: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      62: checkcast     #272                // class java/lang/Number
      65: invokevirtual #275                // Method java/lang/Number.intValue:()I
      68: aload_2
      69: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      72: checkcast     #272                // class java/lang/Number
      75: invokevirtual #275                // Method java/lang/Number.intValue:()I
      78: if_icmpne     148
      81: new           #103                // class kotlin/Pair
      84: dup
      85: aload_2
      86: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      89: aload_1
      90: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      93: checkcast     #272                // class java/lang/Number
      96: invokevirtual #275                // Method java/lang/Number.intValue:()I
      99: aload_2
     100: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     103: checkcast     #272                // class java/lang/Number
     106: invokevirtual #275                // Method java/lang/Number.intValue:()I
     109: if_icmple     127
     112: aload_2
     113: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     116: checkcast     #272                // class java/lang/Number
     119: invokevirtual #275                // Method java/lang/Number.intValue:()I
     122: iconst_1
     123: iadd
     124: goto          139
     127: aload_2
     128: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     131: checkcast     #272                // class java/lang/Number
     134: invokevirtual #275                // Method java/lang/Number.intValue:()I
     137: iconst_1
     138: isub
     139: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     142: invokespecial #112                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     145: goto          440
     148: aload_1
     149: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     152: checkcast     #272                // class java/lang/Number
     155: invokevirtual #275                // Method java/lang/Number.intValue:()I
     158: aload_2
     159: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     162: checkcast     #272                // class java/lang/Number
     165: invokevirtual #275                // Method java/lang/Number.intValue:()I
     168: if_icmpne     238
     171: new           #103                // class kotlin/Pair
     174: dup
     175: aload_1
     176: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     179: checkcast     #272                // class java/lang/Number
     182: invokevirtual #275                // Method java/lang/Number.intValue:()I
     185: aload_2
     186: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     189: checkcast     #272                // class java/lang/Number
     192: invokevirtual #275                // Method java/lang/Number.intValue:()I
     195: if_icmple     213
     198: aload_2
     199: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     202: checkcast     #272                // class java/lang/Number
     205: invokevirtual #275                // Method java/lang/Number.intValue:()I
     208: iconst_1
     209: iadd
     210: goto          225
     213: aload_2
     214: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     217: checkcast     #272                // class java/lang/Number
     220: invokevirtual #275                // Method java/lang/Number.intValue:()I
     223: iconst_1
     224: isub
     225: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     228: aload_2
     229: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     232: invokespecial #112                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     235: goto          440
     238: aload_1
     239: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     242: checkcast     #272                // class java/lang/Number
     245: invokevirtual #275                // Method java/lang/Number.intValue:()I
     248: aload_2
     249: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     252: checkcast     #272                // class java/lang/Number
     255: invokevirtual #275                // Method java/lang/Number.intValue:()I
     258: isub
     259: istore_3
     260: aload_1
     261: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     264: checkcast     #272                // class java/lang/Number
     267: invokevirtual #275                // Method java/lang/Number.intValue:()I
     270: aload_2
     271: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     274: checkcast     #272                // class java/lang/Number
     277: invokevirtual #275                // Method java/lang/Number.intValue:()I
     280: isub
     281: istore        4
     283: iload_3
     284: invokestatic  #281                // Method java/lang/Math.abs:(I)I
     287: iconst_1
     288: if_icmpgt     307
     291: iload_3
     292: invokestatic  #281                // Method java/lang/Math.abs:(I)I
     295: ifle          311
     298: iload         4
     300: invokestatic  #281                // Method java/lang/Math.abs:(I)I
     303: iconst_1
     304: if_icmple     311
     307: iconst_1
     308: goto          312
     311: iconst_0
     312: istore        5
     314: iload         4
     316: invokestatic  #281                // Method java/lang/Math.abs:(I)I
     319: iconst_1
     320: if_icmpgt     339
     323: iload         4
     325: invokestatic  #281                // Method java/lang/Math.abs:(I)I
     328: ifle          343
     331: iload_3
     332: invokestatic  #281                // Method java/lang/Math.abs:(I)I
     335: iconst_1
     336: if_icmple     343
     339: iconst_1
     340: goto          344
     343: iconst_0
     344: istore        6
     346: new           #103                // class kotlin/Pair
     349: dup
     350: iload         5
     352: ifeq          378
     355: aload_2
     356: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     359: checkcast     #272                // class java/lang/Number
     362: invokevirtual #275                // Method java/lang/Number.intValue:()I
     365: iload_3
     366: ifge          373
     369: iconst_m1
     370: goto          374
     373: iconst_1
     374: iadd
     375: goto          388
     378: aload_2
     379: invokevirtual #270                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     382: checkcast     #272                // class java/lang/Number
     385: invokevirtual #275                // Method java/lang/Number.intValue:()I
     388: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     391: iload         6
     393: ifeq          420
     396: aload_2
     397: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     400: checkcast     #272                // class java/lang/Number
     403: invokevirtual #275                // Method java/lang/Number.intValue:()I
     406: iload         4
     408: ifge          415
     411: iconst_m1
     412: goto          416
     415: iconst_1
     416: iadd
     417: goto          430
     420: aload_2
     421: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     424: checkcast     #272                // class java/lang/Number
     427: invokevirtual #275                // Method java/lang/Number.intValue:()I
     430: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     433: invokespecial #112                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     436: goto          440
     439: aload_2
     440: areturn

  private final kotlin.Pair<java.lang.Integer, java.lang.Integer> processStep(java.lang.String, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_2
       1: invokevirtual #295                // Method kotlin/Pair.component1:()Ljava/lang/Object;
       4: checkcast     #272                // class java/lang/Number
       7: invokevirtual #275                // Method java/lang/Number.intValue:()I
      10: istore_3
      11: aload_2
      12: invokevirtual #298                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      15: checkcast     #272                // class java/lang/Number
      18: invokevirtual #275                // Method java/lang/Number.intValue:()I
      21: istore        4
      23: aload_1
      24: astore        5
      26: aload         5
      28: invokevirtual #301                // Method java/lang/String.hashCode:()I
      31: lookupswitch  { // 4
                    68: 86
                    76: 114
                    82: 72
                    85: 100
               default: 194
          }
      72: aload         5
      74: ldc_w         #303                // String R
      77: invokevirtual #306                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      80: ifne          178
      83: goto          194
      86: aload         5
      88: ldc_w         #308                // String D
      91: invokevirtual #306                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      94: ifne          145
      97: goto          194
     100: aload         5
     102: ldc_w         #310                // String U
     105: invokevirtual #306                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     108: ifne          128
     111: goto          194
     114: aload         5
     116: ldc_w         #312                // String L
     119: invokevirtual #306                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     122: ifne          162
     125: goto          194
     128: aload_2
     129: aconst_null
     130: iload         4
     132: iconst_1
     133: isub
     134: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: iconst_1
     138: aconst_null
     139: invokestatic  #316                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     142: goto          202
     145: aload_2
     146: aconst_null
     147: iload         4
     149: iconst_1
     150: iadd
     151: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: iconst_1
     155: aconst_null
     156: invokestatic  #316                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     159: goto          202
     162: aload_2
     163: iload_3
     164: iconst_1
     165: isub
     166: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     169: aconst_null
     170: iconst_2
     171: aconst_null
     172: invokestatic  #316                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     175: goto          202
     178: aload_2
     179: iload_3
     180: iconst_1
     181: iadd
     182: invokestatic  #109                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     185: aconst_null
     186: iconst_2
     187: aconst_null
     188: invokestatic  #316                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     191: goto          202
     194: new           #318                // class java/lang/IllegalStateException
     197: dup
     198: invokespecial #319                // Method java/lang/IllegalStateException."<init>":()V
     201: athrow
     202: areturn
}