package com.aallam.similarity

import kotlin.math.min

/**
 * The Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or
 * substitutions) required to change one string into the other.
 *
 * This implementation uses dynamic programming (Wagner–Fischer algorithm).
 *
 * [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
 */
public class Levenshtein {

    /**
     * The Levenshtein distance, or edit distance, between two words is the minimum number of single-character edits
     * (insertions, deletions or substitutions) required to change one word into the other.
     *
     * It is always at least the difference of the sizes of the two strings.
     * It is at most the length of the longer string.
     * It is `0` if and only if the strings are equal.
     *
     * @param first first string to compare.
     * @param second second string to compare.
     * @param limit the maximum result to compute before stopping, terminating calculation early.
     * @return the computed Levenshtein distance.
     */
    public fun distance(first: CharSequence, second: CharSequence, limit: Int = Int.MAX_VALUE): Int {
        if (first == second) return 0
        if (first.isEmpty()) return second.length
        if (second.isEmpty()) return first.length

        // initial costs is the edit distance from an empty string, which corresponds to the characters to inserts.
        // the array size is : length + 1 (empty string)
        var cost = IntArray(first.length + 1) { it }
        var newCost = IntArray(first.length + 1)

        for (i in 1..second.length) {

            // calculate new costs from the previous row.
            // the first element of the new row is the edit distance (deletes) to match empty string
            newCost[0] = i

            var minCost = i

            // fill in the rest of the row
            for (j in 1..first.length) {
                // if it's the same char at the same position, no edit cost.
                val edit = if (first[j - 1] == second[i - 1]) 0 else 1
                val replace = cost[j - 1] + edit
                val insert = cost[j] + 1
                val delete = newCost[j - 1] + 1
                newCost[j] = minOf(insert, delete, replace)
                minCost = min(minCost, newCost[j])
            }

            if (minCost >= limit) return limit

            // flip references of current and previous row
            val swap = cost
            cost = newCost
            newCost = swap
        }

        return cost.last()
    }
}

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

  public final int distance(java.lang.CharSequence, java.lang.CharSequence, int);
    Code:
       0: aload_1
       1: ldc           #15                 // String first
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String second
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: aload_2
      14: invokestatic  #27                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      17: ifeq          22
      20: iconst_0
      21: ireturn
      22: aload_1
      23: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      28: ifne          35
      31: iconst_1
      32: goto          36
      35: iconst_0
      36: ifeq          46
      39: aload_2
      40: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      45: ireturn
      46: aload_2
      47: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      52: ifne          59
      55: iconst_1
      56: goto          60
      59: iconst_0
      60: ifeq          70
      63: aload_1
      64: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      69: ireturn
      70: iconst_0
      71: istore        5
      73: aload_1
      74: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      79: iconst_1
      80: iadd
      81: istore        6
      83: iload         6
      85: newarray       int
      87: astore        7
      89: iload         5
      91: iload         6
      93: if_icmpge     113
      96: iload         5
      98: istore        8
     100: aload         7
     102: iload         8
     104: iload         8
     106: iastore
     107: iinc          5, 1
     110: goto          89
     113: aload         7
     115: astore        4
     117: aload_1
     118: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     123: iconst_1
     124: iadd
     125: newarray       int
     127: astore        5
     129: iconst_1
     130: istore        6
     132: aload_2
     133: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     138: istore        7
     140: iload         6
     142: iload         7
     144: if_icmpgt     312
     147: aload         5
     149: iconst_0
     150: iload         6
     152: iastore
     153: iload         6
     155: istore        8
     157: iconst_1
     158: istore        9
     160: aload_1
     161: invokeinterface #33,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     166: istore        10
     168: iload         9
     170: iload         10
     172: if_icmpgt     279
     175: aload_1
     176: iload         9
     178: iconst_1
     179: isub
     180: invokeinterface #37,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     185: aload_2
     186: iload         6
     188: iconst_1
     189: isub
     190: invokeinterface #37,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     195: if_icmpne     202
     198: iconst_0
     199: goto          203
     202: iconst_1
     203: istore        11
     205: aload         4
     207: iload         9
     209: iconst_1
     210: isub
     211: iaload
     212: iload         11
     214: iadd
     215: istore        12
     217: aload         4
     219: iload         9
     221: iaload
     222: iconst_1
     223: iadd
     224: istore        13
     226: aload         5
     228: iload         9
     230: iconst_1
     231: isub
     232: iaload
     233: iconst_1
     234: iadd
     235: istore        14
     237: aload         5
     239: iload         9
     241: iload         13
     243: iload         14
     245: iload         12
     247: invokestatic  #43                 // Method java/lang/Math.min:(II)I
     250: invokestatic  #43                 // Method java/lang/Math.min:(II)I
     253: iastore
     254: iload         8
     256: aload         5
     258: iload         9
     260: iaload
     261: invokestatic  #43                 // Method java/lang/Math.min:(II)I
     264: istore        8
     266: iload         9
     268: iload         10
     270: if_icmpeq     279
     273: iinc          9, 1
     276: goto          175
     279: iload         8
     281: iload_3
     282: if_icmplt     287
     285: iload_3
     286: ireturn
     287: aload         4
     289: astore        9
     291: aload         5
     293: astore        4
     295: aload         9
     297: astore        5
     299: iload         6
     301: iload         7
     303: if_icmpeq     312
     306: iinc          6, 1
     309: goto          147
     312: aload         4
     314: invokestatic  #49                 // Method kotlin/collections/ArraysKt.last:([I)I
     317: ireturn

  public static int distance$default(com.aallam.similarity.Levenshtein, java.lang.CharSequence, java.lang.CharSequence, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_4
       3: iand
       4: ifeq          10
       7: ldc           #67                 // int 2147483647
       9: istore_3
      10: aload_0
      11: aload_1
      12: aload_2
      13: iload_3
      14: invokevirtual #69                 // Method distance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;I)I
      17: ireturn
}


package com.aallam.similarity

import kotlin.math.max

/**
 * This distance is computed as levenshtein distance divided by the length of the longest string.
 * The resulting value is always in the interval 0 to 1.
 *
 * [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
 */
public class NormalizedLevenshtein {

    /**
     * Levenshtein distance metric implementation.
     */
    private val levenshtein = Levenshtein()

    /**
     * This distance is computed as levenshtein distance divided by the length of the longest string.
     * The resulting value is always in the interval 0 to 1.
     *
     *  Compute distance as Levenshtein(s1, s2) / max(|s1|, |s2|).
     *
     * @param first left hand side string to compare.
     * @param second right hand side string to compare.
     * @return the computed normalized Levenshtein distance.
     */
    public fun distance(first: CharSequence, second: CharSequence): Double {
        val maxLength = max(first.length, second.length)
        if (maxLength == 0) return 0.0
        return levenshtein.distance(first, second) / maxLength.toDouble()
    }

    /**
     * Compute the similarity between two string.
     * Corresponds to 1.0 - normalized distance.
     *
     * @param lhs left hand side string to compare.
     * @param rhs right hand side string to compare.
     * @return the computer similarity
     */
    public fun similarity(lhs: CharSequence, rhs: CharSequence): Double {
        return 1.0 - distance(lhs, rhs)
    }
}

Compiled from "NormalizedLevenshtein.kt"
public final class com.aallam.similarity.NormalizedLevenshtein {
  private final com.aallam.similarity.Levenshtein levenshtein;

  public com.aallam.similarity.NormalizedLevenshtein();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class com/aallam/similarity/Levenshtein
       8: dup
       9: invokespecial #11                 // Method com/aallam/similarity/Levenshtein."<init>":()V
      12: putfield      #15                 // Field levenshtein:Lcom/aallam/similarity/Levenshtein;
      15: return

  public final double distance(java.lang.CharSequence, java.lang.CharSequence);
    Code:
       0: aload_1
       1: ldc           #22                 // String first
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #30                 // String second
       9: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokeinterface #36,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      18: aload_2
      19: invokeinterface #36,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      24: invokestatic  #42                 // Method java/lang/Math.max:(II)I
      27: istore_3
      28: iload_3
      29: ifne          34
      32: dconst_0
      33: dreturn
      34: aload_0
      35: getfield      #15                 // Field levenshtein:Lcom/aallam/similarity/Levenshtein;
      38: aload_1
      39: aload_2
      40: iconst_0
      41: iconst_4
      42: aconst_null
      43: invokestatic  #46                 // Method com/aallam/similarity/Levenshtein.distance$default:(Lcom/aallam/similarity/Levenshtein;Ljava/lang/CharSequence;Ljava/lang/CharSequence;IILjava/lang/Object;)I
      46: i2d
      47: iload_3
      48: i2d
      49: ddiv
      50: dreturn

  public final double similarity(java.lang.CharSequence, java.lang.CharSequence);
    Code:
       0: aload_1
       1: ldc           #52                 // String lhs
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #54                 // String rhs
       9: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: dconst_1
      13: aload_0
      14: aload_1
      15: aload_2
      16: invokevirtual #56                 // Method distance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)D
      19: dsub
      20: dreturn
}


package com.aallam.similarity

import com.aallam.similarity.internal.Shingle

/**
 * Each input string is converted into a set of n-grams, the Jaccard index is then computed as `|A ∩ B| / |A ∪ B|`.
 *
 * Like Q-Gram distance, the input strings are first converted into sets of n-grams (sequences of n characters, also
 * called k-shingles), but this time the cardinality of each n-gram is not taken into account.
 *
 * Jaccard index is a metric distance.
 *
 * @param k length of k-shingles
 */
public class Jaccard(private val k: Int = 3) {

    /**
     * Compute Jaccard index. `|A ∩ B| / |A ∪ B|`.
     * @param first the first string to compare.
     * @param second the second string to compare.
     */
    public fun similarity(first: String, second: String): Double {
        if (first == second) return 1.0
        val p1 = Shingle.profile(first, k)
        val p2 = Shingle.profile(second, k)
        val union = p1.keys + p2.keys
        val inter = p1.keys.size + p2.keys.size - union.size
        return inter.toDouble() / union.size
    }

    /**
     * Distance is computed as 1 - similarity.
     *
     * @param first the first string to compare.
     * @param second the second string to compare.
     */
    public fun distance(first: String, second: String): Double {
        return 1.0 - similarity(first, second)
    }
}

Compiled from "Jaccard.kt"
public final class com.aallam.similarity.Jaccard {
  private final int k;

  public com.aallam.similarity.Jaccard(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field k:I
       9: return

  public com.aallam.similarity.Jaccard(int, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          8
       6: iconst_3
       7: istore_1
       8: aload_0
       9: iload_1
      10: invokespecial #18                 // Method "<init>":(I)V
      13: return

  public final double similarity(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #23                 // String first
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #31                 // String second
       9: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: aload_2
      14: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      17: ifeq          22
      20: dconst_1
      21: dreturn
      22: getstatic     #41                 // Field com/aallam/similarity/internal/Shingle.Companion:Lcom/aallam/similarity/internal/Shingle$Companion;
      25: aload_1
      26: checkcast     #43                 // class java/lang/CharSequence
      29: aload_0
      30: getfield      #13                 // Field k:I
      33: invokevirtual #49                 // Method com/aallam/similarity/internal/Shingle$Companion.profile:(Ljava/lang/CharSequence;I)Ljava/util/Map;
      36: astore_3
      37: getstatic     #41                 // Field com/aallam/similarity/internal/Shingle.Companion:Lcom/aallam/similarity/internal/Shingle$Companion;
      40: aload_2
      41: checkcast     #43                 // class java/lang/CharSequence
      44: aload_0
      45: getfield      #13                 // Field k:I
      48: invokevirtual #49                 // Method com/aallam/similarity/internal/Shingle$Companion.profile:(Ljava/lang/CharSequence;I)Ljava/util/Map;
      51: astore        4
      53: aload_3
      54: invokeinterface #55,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      59: aload         4
      61: invokeinterface #55,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      66: checkcast     #57                 // class java/lang/Iterable
      69: invokestatic  #63                 // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
      72: astore        5
      74: aload_3
      75: invokeinterface #55,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      80: invokeinterface #69,  1           // InterfaceMethod java/util/Set.size:()I
      85: aload         4
      87: invokeinterface #55,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      92: invokeinterface #69,  1           // InterfaceMethod java/util/Set.size:()I
      97: iadd
      98: aload         5
     100: invokeinterface #69,  1           // InterfaceMethod java/util/Set.size:()I
     105: isub
     106: istore        6
     108: iload         6
     110: i2d
     111: aload         5
     113: invokeinterface #69,  1           // InterfaceMethod java/util/Set.size:()I
     118: i2d
     119: ddiv
     120: dreturn

  public final double distance(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #23                 // String first
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #31                 // String second
       9: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: dconst_1
      13: aload_0
      14: aload_1
      15: aload_2
      16: invokevirtual #79                 // Method similarity:(Ljava/lang/String;Ljava/lang/String;)D
      19: dsub
      20: dreturn

  public com.aallam.similarity.Jaccard();
    Code:
       0: aload_0
       1: iconst_0
       2: iconst_1
       3: aconst_null
       4: invokespecial #81                 // Method "<init>":(IILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return
}


package com.aallam.similarity

/**
 * The Ratcliff/Obershelp algorithm computes the similarity of two strings the doubled number of matching characters
 * divided by the total number of characters in the two strings. Matching characters are those in the longest common
 * subsequence plus, recursively, matching characters in the unmatched region on either side of the longest common
 * subsequence.
 */
public class RatcliffObershelp {

    /**
     * Compute the Ratcliff-Obershelp similarity between strings.
     *
     * @param first the first string to compare.
     * @param second the second string to compare.
     */
    public fun similarity(first: String, second: String): Double {
        if (first == second) return 1.0
        val matches = matchList(first, second)
        val sumOfMatches = matches.sumOf { it.length }
        return 2.0 * sumOfMatches / (first.length + second.length)
    }

    /**
     * Return 1 - similarity.
     *
     * @param first the first string to compare.
     * @param second the second string to compare.
     */
    public fun distance(first: String, second: String): Double {
        return 1.0 - similarity(first, second)
    }

    /**
     * Returns a list of matching substrings between the given [first] and [second] strings.
     *
     * @param first The first string to compare.
     * @param second The second string to compare.
     */
    private fun matchList(first: String, second: String): List<String> {
        val match = frontMaxMatch(first, second)
        if (match.isEmpty()) return emptyList()
        val frontQueue = matchList(first.substringBefore(match), second.substringBefore(match))
        val endQueue = matchList(first.substringAfter(match), second.substringAfter(match))
        return listOf(match) + frontQueue + endQueue
    }

    /**
     * Returns the longest substring that occurs at the beginning of both the [first] and [second] strings.
     *
     * @param first the first string to compare.
     * @param second the second string to compare.
     */
    private fun frontMaxMatch(first: String, second: String): String {
        var longestSubstring = ""
        for (i in first.indices) {
            for (j in i + 1..first.length) {
                val substring = first.substring(i, j)
                if (second.contains(substring) && substring.length > longestSubstring.length) {
                    longestSubstring = substring
                }
            }
        }
        return longestSubstring
    }
}

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

  public final double similarity(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String first
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String second
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: aload_2
      14: invokestatic  #27                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      17: ifeq          22
      20: dconst_1
      21: dreturn
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokespecial #31                 // Method matchList:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      28: astore_3
      29: aload_3
      30: checkcast     #33                 // class java/lang/Iterable
      33: astore        5
      35: iconst_0
      36: istore        6
      38: aload         5
      40: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        7
      47: aload         7
      49: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          97
      57: aload         7
      59: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        8
      66: iload         6
      68: aload         8
      70: checkcast     #49                 // class java/lang/String
      73: astore        9
      75: istore        11
      77: iconst_0
      78: istore        10
      80: aload         9
      82: invokevirtual #53                 // Method java/lang/String.length:()I
      85: istore        12
      87: iload         11
      89: iload         12
      91: iadd
      92: istore        6
      94: goto          47
      97: iload         6
      99: istore        4
     101: ldc2_w        #54                 // double 2.0d
     104: iload         4
     106: i2d
     107: dmul
     108: aload_1
     109: invokevirtual #53                 // Method java/lang/String.length:()I
     112: aload_2
     113: invokevirtual #53                 // Method java/lang/String.length:()I
     116: iadd
     117: i2d
     118: ddiv
     119: dreturn

  public final double distance(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String first
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String second
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: dconst_1
      13: aload_0
      14: aload_1
      15: aload_2
      16: invokevirtual #67                 // Method similarity:(Ljava/lang/String;Ljava/lang/String;)D
      19: dsub
      20: dreturn

  private final java.util.List<java.lang.String> matchList(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokespecial #72                 // Method frontMaxMatch:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
       6: astore_3
       7: aload_3
       8: checkcast     #74                 // class java/lang/CharSequence
      11: invokeinterface #75,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      16: ifne          23
      19: iconst_1
      20: goto          24
      23: iconst_0
      24: ifeq          31
      27: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      30: areturn
      31: aload_0
      32: aload_1
      33: aload_3
      34: aconst_null
      35: iconst_2
      36: aconst_null
      37: invokestatic  #87                 // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      40: aload_2
      41: aload_3
      42: aconst_null
      43: iconst_2
      44: aconst_null
      45: invokestatic  #87                 // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      48: invokespecial #31                 // Method matchList:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      51: astore        4
      53: aload_0
      54: aload_1
      55: aload_3
      56: aconst_null
      57: iconst_2
      58: aconst_null
      59: invokestatic  #90                 // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      62: aload_2
      63: aload_3
      64: aconst_null
      65: iconst_2
      66: aconst_null
      67: invokestatic  #90                 // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      70: invokespecial #31                 // Method matchList:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      73: astore        5
      75: aload_3
      76: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      79: checkcast     #96                 // class java/util/Collection
      82: aload         4
      84: checkcast     #33                 // class java/lang/Iterable
      87: invokestatic  #100                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
      90: checkcast     #96                 // class java/util/Collection
      93: aload         5
      95: checkcast     #33                 // class java/lang/Iterable
      98: invokestatic  #100                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     101: areturn

  private final java.lang.String frontMaxMatch(java.lang.String, java.lang.String);
    Code:
       0: ldc           #105                // String
       2: astore_3
       3: iconst_0
       4: istore        4
       6: aload_1
       7: checkcast     #74                 // class java/lang/CharSequence
      10: invokeinterface #75,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      15: istore        5
      17: iload         4
      19: iload         5
      21: if_icmpge     111
      24: iload         4
      26: iconst_1
      27: iadd
      28: istore        6
      30: aload_1
      31: invokevirtual #53                 // Method java/lang/String.length:()I
      34: istore        7
      36: iload         6
      38: iload         7
      40: if_icmpgt     105
      43: aload_1
      44: iload         4
      46: iload         6
      48: invokevirtual #109                // Method java/lang/String.substring:(II)Ljava/lang/String;
      51: dup
      52: ldc           #111                // String substring(...)
      54: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      57: astore        8
      59: aload_2
      60: checkcast     #74                 // class java/lang/CharSequence
      63: aload         8
      65: checkcast     #74                 // class java/lang/CharSequence
      68: iconst_0
      69: iconst_2
      70: aconst_null
      71: invokestatic  #118                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
      74: ifeq          92
      77: aload         8
      79: invokevirtual #53                 // Method java/lang/String.length:()I
      82: aload_3
      83: invokevirtual #53                 // Method java/lang/String.length:()I
      86: if_icmple     92
      89: aload         8
      91: astore_3
      92: iload         6
      94: iload         7
      96: if_icmpeq     105
      99: iinc          6, 1
     102: goto          43
     105: iinc          4, 1
     108: goto          17
     111: aload_3
     112: areturn
}


package com.aallam.similarity.internal

/**
 * Similarities that rely on set operations (like cosine similarity or jaccard index).
 */
internal interface Shingle {

    /**
     * Compute and return the profile of string as defined by [Ukkonen](https://www.cs.helsinki.fi/u/ukkonen/TCS92.pdf).
     *
     * The profile is the number of occurrences of k-shingles, and is used to compute q-gram similarity, Jaccard index,
     * etc.
     *
     * k-shingling is the operation of transforming a string (or text document) into a set of n-grams, which can be used to
     * measure the similarity between two strings or documents.
     *
     * Generally speaking, a k-gram is any sequence of [k] tokens.
     * Multiple subsequent spaces are replaced by a single space, and a k-gram is a sequence of k characters.
     *
     * Default value of [k] is `3`. A good rule of thumb is to imagine that there are only 20 characters and estimate the
     * number of k-shingles as 20^k. For small documents like e-mails, k = 5 is a recommended value. For large documents,
     * such as research articles, k = 9 is considered a safe choice.
     *
     * The memory requirement of the profile can be up to [k] * [string]`.length`.
     *
     * @param string input string
     * @param k length of k-shingles
     * @return the profile of the provided string
     */
    fun profile(string: CharSequence, k: Int = 3): Profile {
        require(k > 0) { "k should be positive" }
        val filtered = spaces.replace(string, " ")
        return filtered.windowed(size = k).groupingBy { it }.eachCount()
    }

    companion object : Shingle {

        /**
         * Regex for subsequent spaces.
         */
        private val spaces = Regex("\\s+")
    }
}

/**
 * The number of occurrences of k-shingles.
 */
internal typealias Profile = Map<String, Int>

Compiled from "Shingle.kt"
public final class com.aallam.similarity.internal.Shingle$DefaultImpls {
  public static java.util.Map<java.lang.String, java.lang.Integer> profile(com.aallam.similarity.internal.Shingle, java.lang.CharSequence, int);
    Code:
       0: aload_1
       1: ldc           #10                 // String string
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_2
       7: ifle          14
      10: iconst_1
      11: goto          15
      14: iconst_0
      15: ifne          38
      18: iconst_0
      19: istore        4
      21: ldc           #18                 // String k should be positive
      23: astore        4
      25: new           #20                 // class java/lang/IllegalArgumentException
      28: dup
      29: aload         4
      31: invokevirtual #24                 // Method java/lang/Object.toString:()Ljava/lang/String;
      34: invokespecial #28                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      37: athrow
      38: invokestatic  #34                 // Method com/aallam/similarity/internal/Shingle$Companion.access$getSpaces$p:()Lkotlin/text/Regex;
      41: aload_1
      42: ldc           #36                 // String
      44: invokevirtual #42                 // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      47: astore_3
      48: aload_3
      49: checkcast     #44                 // class java/lang/CharSequence
      52: iload_2
      53: iconst_0
      54: iconst_0
      55: bipush        6
      57: aconst_null
      58: invokestatic  #50                 // Method kotlin/text/StringsKt.windowed$default:(Ljava/lang/CharSequence;IIZILjava/lang/Object;)Ljava/util/List;
      61: checkcast     #52                 // class java/lang/Iterable
      64: astore        4
      66: iconst_0
      67: istore        5
      69: new           #54                 // class com/aallam/similarity/internal/Shingle$DefaultImpls$profile$$inlined$groupingBy$1
      72: dup
      73: aload         4
      75: invokespecial #57                 // Method com/aallam/similarity/internal/Shingle$DefaultImpls$profile$$inlined$groupingBy$1."<init>":(Ljava/lang/Iterable;)V
      78: checkcast     #59                 // class kotlin/collections/Grouping
      81: invokestatic  #65                 // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      84: areturn

  public static java.util.Map profile$default(com.aallam.similarity.internal.Shingle, java.lang.CharSequence, int, int, java.lang.Object);
    Code:
       0: aload         4
       2: ifnull        15
       5: new           #80                 // class java/lang/UnsupportedOperationException
       8: dup
       9: ldc           #82                 // String Super calls with default arguments not supported in this target, function: profile
      11: invokespecial #83                 // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
      14: athrow
      15: iload_3
      16: iconst_2
      17: iand
      18: ifeq          23
      21: iconst_3
      22: istore_2
      23: aload_0
      24: aload_1
      25: iload_2
      26: invokeinterface #88,  3           // InterfaceMethod com/aallam/similarity/internal/Shingle.profile:(Ljava/lang/CharSequence;I)Ljava/util/Map;
      31: areturn
}

Compiled from "Shingle.kt"
public final class com.aallam.similarity.internal.ShingleKt {
}

Compiled from "Shingle.kt"
public interface com.aallam.similarity.internal.Shingle {
  public static final com.aallam.similarity.internal.Shingle$Companion Companion;

  public abstract java.util.Map<java.lang.String, java.lang.Integer> profile(java.lang.CharSequence, int);

  static {};
    Code:
       0: getstatic     #16                 // Field com/aallam/similarity/internal/Shingle$Companion.$$INSTANCE:Lcom/aallam/similarity/internal/Shingle$Companion;
       3: putstatic     #19                 // Field Companion:Lcom/aallam/similarity/internal/Shingle$Companion;
       6: return
}

Compiled from "_Collections.kt"
public final class com.aallam.similarity.internal.Shingle$DefaultImpls$profile$$inlined$groupingBy$1 implements kotlin.collections.Grouping<java.lang.String, java.lang.String> {
  final java.lang.Iterable $this_groupingBy;

  public com.aallam.similarity.internal.Shingle$DefaultImpls$profile$$inlined$groupingBy$1(java.lang.Iterable);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<java.lang.String> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       4: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: areturn

  public java.lang.String keyOf(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #37                 // class java/lang/String
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: areturn
}

Compiled from "Shingle.kt"
public final class com.aallam.similarity.internal.Shingle$Companion implements com.aallam.similarity.internal.Shingle {
  static final com.aallam.similarity.internal.Shingle$Companion $$INSTANCE;

  private static final kotlin.text.Regex spaces;

  private com.aallam.similarity.internal.Shingle$Companion();
    Code:
       0: aload_0
       1: invokespecial #10                 // Method java/lang/Object."<init>":()V
       4: return

  public java.util.Map<java.lang.String, java.lang.Integer> profile(java.lang.CharSequence, int);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokestatic  #21                 // Method com/aallam/similarity/internal/Shingle$DefaultImpls.profile:(Lcom/aallam/similarity/internal/Shingle;Ljava/lang/CharSequence;I)Ljava/util/Map;
       6: areturn

  public static final kotlin.text.Regex access$getSpaces$p();
    Code:
       0: getstatic     #31                 // Field spaces:Lkotlin/text/Regex;
       3: areturn

  static {};
    Code:
       0: new           #2                  // class com/aallam/similarity/internal/Shingle$Companion
       3: dup
       4: invokespecial #33                 // Method "<init>":()V
       7: putstatic     #36                 // Field $$INSTANCE:Lcom/aallam/similarity/internal/Shingle$Companion;
      10: new           #38                 // class kotlin/text/Regex
      13: dup
      14: ldc           #40                 // String \\s+
      16: invokespecial #43                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      19: putstatic     #31                 // Field spaces:Lkotlin/text/Regex;
      22: return
}


package day07

data class File(
    val name: String,
    val size: Int,
)

data class Directory(
    val name: String,
    val directories: MutableList<Directory> = mutableListOf(),
    val files: MutableList<File> = mutableListOf(),
) {
    // must not be in the constructor
    lateinit var parent: Directory

    fun size(): Int = files.sumOf { it.size } + directories.sumOf { it.size() }
    fun children(): List<Directory> = directories + directories.flatMap { it.children() }
}

private fun root() = Directory(name = "/").apply { parent = this }

/** Return parent or child directory depending on command */
private fun Directory.cd(cmd: String): Directory =
    when (val dir = cmd.substring(5)) {
        ".." -> parent
        else -> directories.firstOrNull { it.name == dir }
            ?: Directory(name = dir)
                .apply { parent = this@cd }
                .also { directories.add(it) }
    }

/** Create and add file to current directory. Return current directory */
private fun Directory.addFile(path: String): Directory = apply {
    val (size, name) = path.split(' ')
    if (files.none { it.name == name }) {
        files += File(
            name = name,
            size = size.toInt()
        )
    }
}

class Day07 {

    fun parse1(input: String): Directory =
        root().apply {
            input.lines()
                .drop(1) // first line is "$ cd /" -> root
                .fold(this) { dir, line ->
                    when {
                        line == "$ ls" -> dir// do nothing
                        line.startsWith("$ cd ") -> dir.cd(line)// move to directory (create it if necessary)
                        line.startsWith("dir ") -> dir // do nothing (directories are created on 'cd')
                        line[0].isDigit() -> dir.addFile(line)// add file to directory
                        else -> throw IllegalStateException("Invalid line: $line")
                    }
                }
        }

    fun part1(root: Directory): Int =
        root.children()
            .map { it.size() }
            .filter { it < 100_000 }
            .sum()

    fun part2(root: Directory): Int {
        TODO()
    }

}

Compiled from "Day07.kt"
public final class day07.Day07Kt {
  private static final day07.Directory root();
    Code:
       0: new           #8                  // class day07/Directory
       3: dup
       4: ldc           #10                 // String /
       6: aconst_null
       7: aconst_null
       8: bipush        6
      10: aconst_null
      11: invokespecial #14                 // Method day07/Directory."<init>":(Ljava/lang/String;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      14: astore_0
      15: aload_0
      16: astore_1
      17: iconst_0
      18: istore_2
      19: aload_1
      20: aload_1
      21: invokevirtual #18                 // Method day07/Directory.setParent:(Lday07/Directory;)V
      24: aload_0
      25: areturn

  private static final day07.Directory cd(day07.Directory, java.lang.String);
    Code:
       0: aload_1
       1: iconst_5
       2: invokevirtual #30                 // Method java/lang/String.substring:(I)Ljava/lang/String;
       5: dup
       6: ldc           #32                 // String substring(...)
       8: invokestatic  #38                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      11: astore_2
      12: aload_2
      13: ldc           #40                 // String ..
      15: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      18: ifeq          28
      21: aload_0
      22: invokevirtual #47                 // Method day07/Directory.getParent:()Lday07/Directory;
      25: goto          149
      28: aload_0
      29: invokevirtual #51                 // Method day07/Directory.getDirectories:()Ljava/util/List;
      32: checkcast     #53                 // class java/lang/Iterable
      35: astore_3
      36: iconst_0
      37: istore        4
      39: aload_3
      40: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        5
      47: aload         5
      49: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          93
      57: aload         5
      59: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        6
      66: aload         6
      68: checkcast     #8                  // class day07/Directory
      71: astore        7
      73: iconst_0
      74: istore        8
      76: aload         7
      78: invokevirtual #71                 // Method day07/Directory.getName:()Ljava/lang/String;
      81: aload_2
      82: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      85: ifeq          47
      88: aload         6
      90: goto          94
      93: aconst_null
      94: checkcast     #8                  // class day07/Directory
      97: dup
      98: ifnonnull     149
     101: pop
     102: new           #8                  // class day07/Directory
     105: dup
     106: aload_2
     107: aconst_null
     108: aconst_null
     109: bipush        6
     111: aconst_null
     112: invokespecial #14                 // Method day07/Directory."<init>":(Ljava/lang/String;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     115: astore_3
     116: aload_3
     117: astore        4
     119: iconst_0
     120: istore        5
     122: aload         4
     124: aload_0
     125: invokevirtual #18                 // Method day07/Directory.setParent:(Lday07/Directory;)V
     128: aload_3
     129: astore_3
     130: aload_3
     131: astore        4
     133: iconst_0
     134: istore        5
     136: aload_0
     137: invokevirtual #51                 // Method day07/Directory.getDirectories:()Ljava/util/List;
     140: aload         4
     142: invokeinterface #77,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     147: pop
     148: aload_3
     149: areturn

  private static final day07.Directory addFile(day07.Directory, java.lang.String);
    Code:
       0: aload_0
       1: astore_2
       2: aload_2
       3: astore_3
       4: iconst_0
       5: istore        4
       7: aload_1
       8: checkcast     #94                 // class java/lang/CharSequence
      11: iconst_1
      12: newarray       char
      14: astore        5
      16: aload         5
      18: iconst_0
      19: bipush        32
      21: castore
      22: aload         5
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #100                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      32: astore        6
      34: aload         6
      36: iconst_0
      37: invokeinterface #104,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #26                 // class java/lang/String
      45: astore        5
      47: aload         6
      49: iconst_1
      50: invokeinterface #104,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #26                 // class java/lang/String
      58: astore        7
      60: aload_3
      61: invokevirtual #107                // Method day07/Directory.getFiles:()Ljava/util/List;
      64: checkcast     #53                 // class java/lang/Iterable
      67: astore        8
      69: iconst_0
      70: istore        9
      72: aload         8
      74: instanceof    #109                // class java/util/Collection
      77: ifeq          97
      80: aload         8
      82: checkcast     #109                // class java/util/Collection
      85: invokeinterface #112,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      90: ifeq          97
      93: iconst_1
      94: goto          153
      97: aload         8
      99: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        10
     106: aload         10
     108: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          152
     116: aload         10
     118: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: astore        11
     125: aload         11
     127: checkcast     #114                // class day07/File
     130: astore        12
     132: iconst_0
     133: istore        13
     135: aload         12
     137: invokevirtual #115                // Method day07/File.getName:()Ljava/lang/String;
     140: aload         7
     142: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     145: ifeq          106
     148: iconst_0
     149: goto          153
     152: iconst_1
     153: ifeq          183
     156: aload_3
     157: invokevirtual #107                // Method day07/Directory.getFiles:()Ljava/util/List;
     160: checkcast     #109                // class java/util/Collection
     163: new           #114                // class day07/File
     166: dup
     167: aload         7
     169: aload         5
     171: invokestatic  #121                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     174: invokespecial #124                // Method day07/File."<init>":(Ljava/lang/String;I)V
     177: invokeinterface #125,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     182: pop
     183: nop
     184: aload_2
     185: areturn

  public static final day07.Directory access$root();
    Code:
       0: invokestatic  #138                // Method root:()Lday07/Directory;
       3: areturn

  public static final day07.Directory access$cd(day07.Directory, java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #141                // Method cd:(Lday07/Directory;Ljava/lang/String;)Lday07/Directory;
       5: areturn

  public static final day07.Directory access$addFile(day07.Directory, java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #145                // Method addFile:(Lday07/Directory;Ljava/lang/String;)Lday07/Directory;
       5: areturn
}

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

  public final day07.Directory parse1(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String input
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #27                 // Method day07/Day07Kt.access$root:()Lday07/Directory;
       9: astore_2
      10: aload_2
      11: astore_3
      12: iconst_0
      13: istore        4
      15: aload_1
      16: checkcast     #29                 // class java/lang/CharSequence
      19: invokestatic  #35                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      22: checkcast     #37                 // class java/lang/Iterable
      25: iconst_1
      26: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      29: checkcast     #37                 // class java/lang/Iterable
      32: astore        5
      34: nop
      35: iconst_0
      36: istore        6
      38: aload_3
      39: astore        7
      41: aload         5
      43: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        8
      50: aload         8
      52: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          196
      60: aload         8
      62: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        9
      69: aload         7
      71: aload         9
      73: checkcast     #59                 // class java/lang/String
      76: astore        10
      78: astore        11
      80: iconst_0
      81: istore        12
      83: nop
      84: aload         10
      86: ldc           #61                 // String $ ls
      88: invokestatic  #65                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      91: ifeq          99
      94: aload         11
      96: goto          190
      99: aload         10
     101: ldc           #67                 // String $ cd
     103: iconst_0
     104: iconst_2
     105: aconst_null
     106: invokestatic  #71                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     109: ifeq          122
     112: aload         11
     114: aload         10
     116: invokestatic  #75                 // Method day07/Day07Kt.access$cd:(Lday07/Directory;Ljava/lang/String;)Lday07/Directory;
     119: goto          190
     122: aload         10
     124: ldc           #77                 // String dir
     126: iconst_0
     127: iconst_2
     128: aconst_null
     129: invokestatic  #71                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     132: ifeq          140
     135: aload         11
     137: goto          190
     140: aload         10
     142: iconst_0
     143: invokevirtual #81                 // Method java/lang/String.charAt:(I)C
     146: invokestatic  #87                 // Method java/lang/Character.isDigit:(C)Z
     149: ifeq          162
     152: aload         11
     154: aload         10
     156: invokestatic  #90                 // Method day07/Day07Kt.access$addFile:(Lday07/Directory;Ljava/lang/String;)Lday07/Directory;
     159: goto          190
     162: new           #92                 // class java/lang/IllegalStateException
     165: dup
     166: new           #94                 // class java/lang/StringBuilder
     169: dup
     170: invokespecial #95                 // Method java/lang/StringBuilder."<init>":()V
     173: ldc           #97                 // String Invalid line:
     175: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     178: aload         10
     180: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     183: invokevirtual #105                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     186: invokespecial #108                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     189: athrow
     190: nop
     191: astore        7
     193: goto          50
     196: nop
     197: nop
     198: aload_2
     199: areturn

  public final int part1(day07.Directory);
    Code:
       0: aload_1
       1: ldc           #128                // String root
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #132                // Method day07/Directory.children:()Ljava/util/List;
      10: checkcast     #37                 // class java/lang/Iterable
      13: astore_2
      14: nop
      15: iconst_0
      16: istore_3
      17: aload_2
      18: astore        4
      20: new           #134                // class java/util/ArrayList
      23: dup
      24: aload_2
      25: bipush        10
      27: invokestatic  #138                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      30: invokespecial #141                // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #143                // class java/util/Collection
      36: astore        5
      38: iconst_0
      39: istore        6
      41: aload         4
      43: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        7
      50: aload         7
      52: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          103
      60: aload         7
      62: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        8
      69: aload         5
      71: aload         8
      73: checkcast     #124                // class day07/Directory
      76: astore        9
      78: astore        11
      80: iconst_0
      81: istore        10
      83: aload         9
      85: invokevirtual #147                // Method day07/Directory.size:()I
      88: invokestatic  #153                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: aload         11
      93: swap
      94: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      99: pop
     100: goto          50
     103: aload         5
     105: checkcast     #159                // class java/util/List
     108: nop
     109: checkcast     #37                 // class java/lang/Iterable
     112: astore_2
     113: nop
     114: iconst_0
     115: istore_3
     116: aload_2
     117: astore        4
     119: new           #134                // class java/util/ArrayList
     122: dup
     123: invokespecial #160                // Method java/util/ArrayList."<init>":()V
     126: checkcast     #143                // class java/util/Collection
     129: astore        5
     131: iconst_0
     132: istore        6
     134: aload         4
     136: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        7
     143: aload         7
     145: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          203
     153: aload         7
     155: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: astore        8
     162: aload         8
     164: checkcast     #162                // class java/lang/Number
     167: invokevirtual #165                // Method java/lang/Number.intValue:()I
     170: istore        9
     172: iconst_0
     173: istore        10
     175: iload         9
     177: ldc           #166                // int 100000
     179: if_icmpge     186
     182: iconst_1
     183: goto          187
     186: iconst_0
     187: ifeq          143
     190: aload         5
     192: aload         8
     194: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     199: pop
     200: goto          143
     203: aload         5
     205: checkcast     #159                // class java/util/List
     208: nop
     209: checkcast     #37                 // class java/lang/Iterable
     212: invokestatic  #170                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     215: ireturn

  public final int part2(day07.Directory);
    Code:
       0: aload_1
       1: ldc           #128                // String root
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #188                // class kotlin/NotImplementedError
       9: dup
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokespecial #191                // Method kotlin/NotImplementedError."<init>":(Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      16: athrow
}


package day04

private typealias Assignments = Pair<IntRange, IntRange>

private fun String.toIntRange(): IntRange = split("-").map { it.toInt() }.let { it[0]..it[1] }

// anonymous function
private val hasCompleteOverlap = fun(assignments: Assignments): Boolean {
    with(assignments) {
        return first.subtract(second).isEmpty() || second.subtract(first).isEmpty()
    }
}

// lambda
private val hasOverlap = { assignments: Assignments ->
    assignments.first.intersect(assignments.second).isNotEmpty()
}

class Day04 {

    fun parse(input: String): List<Assignments> =
        input
            .lines()
            .map { line -> line.split(",") }
            .map { (first, second) ->
                Assignments(
                    first = first.toIntRange(),
                    second = second.toIntRange()
                )
            }

    fun part1(parsed: List<Assignments>): Int = parsed.count(hasCompleteOverlap)

    fun part2(parsed: List<Assignments>): Int = parsed.count(hasOverlap)

}

Compiled from "Day04.kt"
public final class day04.Day04Kt {
  private static final kotlin.jvm.functions.Function1<kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange>, java.lang.Boolean> hasCompleteOverlap;

  private static final kotlin.jvm.functions.Function1<kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange>, java.lang.Boolean> hasOverlap;

  private static final kotlin.ranges.IntRange toIntRange(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #8                  // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #10                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #12                 // String -
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #18                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #20                 // class java/lang/Iterable
      26: astore_1
      27: iconst_0
      28: istore_2
      29: aload_1
      30: astore_3
      31: new           #22                 // class java/util/ArrayList
      34: dup
      35: aload_1
      36: bipush        10
      38: invokestatic  #28                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokespecial #32                 // Method java/util/ArrayList."<init>":(I)V
      44: checkcast     #34                 // class java/util/Collection
      47: astore        4
      49: iconst_0
      50: istore        5
      52: aload_3
      53: invokeinterface #38,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        6
      60: aload         6
      62: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          114
      70: aload         6
      72: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        7
      79: aload         4
      81: aload         7
      83: checkcast     #10                 // class java/lang/String
      86: astore        8
      88: astore        10
      90: iconst_0
      91: istore        9
      93: aload         8
      95: invokestatic  #54                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      98: nop
      99: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: aload         10
     104: swap
     105: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     110: pop
     111: goto          60
     114: aload         4
     116: checkcast     #64                 // class java/util/List
     119: nop
     120: astore_2
     121: iconst_0
     122: istore_3
     123: new           #66                 // class kotlin/ranges/IntRange
     126: dup
     127: aload_2
     128: iconst_0
     129: invokeinterface #70,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #72                 // class java/lang/Number
     137: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     140: aload_2
     141: iconst_1
     142: invokeinterface #70,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: checkcast     #72                 // class java/lang/Number
     150: invokevirtual #76                 // Method java/lang/Number.intValue:()I
     153: invokespecial #79                 // Method kotlin/ranges/IntRange."<init>":(II)V
     156: nop
     157: areturn

  private static final boolean hasCompleteOverlap$lambda$3(kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange>);
    Code:
       0: aload_0
       1: astore_1
       2: iconst_0
       3: istore_2
       4: aload_1
       5: invokevirtual #103                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       8: checkcast     #20                 // class java/lang/Iterable
      11: aload_1
      12: invokevirtual #106                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      15: checkcast     #20                 // class java/lang/Iterable
      18: invokestatic  #110                // Method kotlin/collections/CollectionsKt.subtract:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      21: invokeinterface #115,  1          // InterfaceMethod java/util/Set.isEmpty:()Z
      26: ifne          54
      29: aload_1
      30: invokevirtual #106                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      33: checkcast     #20                 // class java/lang/Iterable
      36: aload_1
      37: invokevirtual #103                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      40: checkcast     #20                 // class java/lang/Iterable
      43: invokestatic  #110                // Method kotlin/collections/CollectionsKt.subtract:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      46: invokeinterface #115,  1          // InterfaceMethod java/util/Set.isEmpty:()Z
      51: ifeq          58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: ireturn

  private static final boolean hasOverlap$lambda$4(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc           #121                // String assignments
       3: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #103                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      10: checkcast     #20                 // class java/lang/Iterable
      13: aload_0
      14: invokevirtual #106                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      17: checkcast     #20                 // class java/lang/Iterable
      20: invokestatic  #130                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      23: checkcast     #34                 // class java/util/Collection
      26: invokeinterface #131,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      31: ifne          38
      34: iconst_1
      35: goto          39
      38: iconst_0
      39: ireturn

  public static final kotlin.jvm.functions.Function1 access$getHasCompleteOverlap$p();
    Code:
       0: getstatic     #137                // Field hasCompleteOverlap:Lkotlin/jvm/functions/Function1;
       3: areturn

  public static final kotlin.jvm.functions.Function1 access$getHasOverlap$p();
    Code:
       0: getstatic     #141                // Field hasOverlap:Lkotlin/jvm/functions/Function1;
       3: areturn

  public static final kotlin.ranges.IntRange access$toIntRange(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #144                // Method toIntRange:(Ljava/lang/String;)Lkotlin/ranges/IntRange;
       4: areturn

  static {};
    Code:
       0: invokedynamic #164,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       5: putstatic     #137                // Field hasCompleteOverlap:Lkotlin/jvm/functions/Function1;
       8: invokedynamic #168,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      13: putstatic     #141                // Field hasOverlap:Lkotlin/jvm/functions/Function1;
      16: return
}

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

  public final java.util.List<kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange>> parse(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/CharSequence
      10: invokestatic  #30                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      13: checkcast     #32                 // class java/lang/Iterable
      16: astore_2
      17: nop
      18: iconst_0
      19: istore_3
      20: aload_2
      21: astore        4
      23: new           #34                 // class java/util/ArrayList
      26: dup
      27: aload_2
      28: bipush        10
      30: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #45                 // class java/util/Collection
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload         4
      46: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        7
      53: aload         7
      55: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          125
      63: aload         7
      65: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        8
      72: aload         5
      74: aload         8
      76: checkcast     #61                 // class java/lang/String
      79: astore        9
      81: astore        13
      83: iconst_0
      84: istore        10
      86: aload         9
      88: checkcast     #24                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #61                 // class java/lang/String
      95: astore        11
      97: aload         11
      99: iconst_0
     100: ldc           #63                 // String ,
     102: aastore
     103: aload         11
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #67                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: aload         13
     115: swap
     116: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          53
     125: aload         5
     127: checkcast     #73                 // class java/util/List
     130: nop
     131: checkcast     #32                 // class java/lang/Iterable
     134: astore_2
     135: nop
     136: iconst_0
     137: istore_3
     138: aload_2
     139: astore        4
     141: new           #34                 // class java/util/ArrayList
     144: dup
     145: aload_2
     146: bipush        10
     148: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     151: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
     154: checkcast     #45                 // class java/util/Collection
     157: astore        5
     159: iconst_0
     160: istore        6
     162: aload         4
     164: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     169: astore        7
     171: aload         7
     173: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     178: ifeq          260
     181: aload         7
     183: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     188: astore        8
     190: aload         5
     192: aload         8
     194: checkcast     #73                 // class java/util/List
     197: astore        9
     199: astore        13
     201: iconst_0
     202: istore        10
     204: aload         9
     206: iconst_0
     207: invokeinterface #77,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     212: checkcast     #61                 // class java/lang/String
     215: astore        11
     217: aload         9
     219: iconst_1
     220: invokeinterface #77,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     225: checkcast     #61                 // class java/lang/String
     228: astore        12
     230: new           #79                 // class kotlin/Pair
     233: dup
     234: aload         11
     236: invokestatic  #85                 // Method day04/Day04Kt.access$toIntRange:(Ljava/lang/String;)Lkotlin/ranges/IntRange;
     239: aload         12
     241: invokestatic  #85                 // Method day04/Day04Kt.access$toIntRange:(Ljava/lang/String;)Lkotlin/ranges/IntRange;
     244: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     247: nop
     248: aload         13
     250: swap
     251: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     256: pop
     257: goto          171
     260: aload         5
     262: checkcast     #73                 // class java/util/List
     265: nop
     266: areturn

  public final int part1(java.util.List<kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange>>);
    Code:
       0: aload_1
       1: ldc           #109                // String parsed
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #32                 // class java/lang/Iterable
      10: astore_2
      11: invokestatic  #113                // Method day04/Day04Kt.access$getHasCompleteOverlap$p:()Lkotlin/jvm/functions/Function1;
      14: astore_3
      15: iconst_0
      16: istore        4
      18: aload_2
      19: instanceof    #45                 // class java/util/Collection
      22: ifeq          41
      25: aload_2
      26: checkcast     #45                 // class java/util/Collection
      29: invokeinterface #116,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      34: ifeq          41
      37: iconst_0
      38: goto          104
      41: iconst_0
      42: istore        5
      44: aload_2
      45: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          102
      62: aload         6
      64: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload_3
      72: aload         7
      74: invokeinterface #122,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      79: checkcast     #124                // class java/lang/Boolean
      82: invokevirtual #127                // Method java/lang/Boolean.booleanValue:()Z
      85: ifeq          52
      88: iinc          5, 1
      91: iload         5
      93: ifge          52
      96: invokestatic  #130                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
      99: goto          52
     102: iload         5
     104: ireturn

  public final int part2(java.util.List<kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange>>);
    Code:
       0: aload_1
       1: ldc           #109                // String parsed
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #32                 // class java/lang/Iterable
      10: astore_2
      11: invokestatic  #141                // Method day04/Day04Kt.access$getHasOverlap$p:()Lkotlin/jvm/functions/Function1;
      14: astore_3
      15: iconst_0
      16: istore        4
      18: aload_2
      19: instanceof    #45                 // class java/util/Collection
      22: ifeq          41
      25: aload_2
      26: checkcast     #45                 // class java/util/Collection
      29: invokeinterface #116,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      34: ifeq          41
      37: iconst_0
      38: goto          104
      41: iconst_0
      42: istore        5
      44: aload_2
      45: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          102
      62: aload         6
      64: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload_3
      72: aload         7
      74: invokeinterface #122,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      79: checkcast     #124                // class java/lang/Boolean
      82: invokevirtual #127                // Method java/lang/Boolean.booleanValue:()Z
      85: ifeq          52
      88: iinc          5, 1
      91: iload         5
      93: ifge          52
      96: invokestatic  #130                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
      99: goto          52
     102: iload         5
     104: ireturn
}


package day03

private val itemPriorities: Map<Char, Int> = (('a'..'z') + ('A'..'Z')).mapIndexed { i, c -> c to i + 1 }.toMap()

private typealias RuckSack = Pair<Set<Char>, Set<Char>>

class Day03 {

    fun parse(input: String): List<RuckSack> =
        input.lines().map { line ->
            RuckSack(
                first = line.substring(0, line.length / 2).toSet(),
                second = line.substring(line.length / 2).toSet()
            )
        }

    fun part1(parsed: List<RuckSack>): Int =
        parsed.map { (first, second) -> first.intersect(second).first() }
            .sumOf { itemPriorities[it]!! }

    fun part2(parsed: List<RuckSack>): Int =
        parsed.map { it.first + it.second }
            .windowed(size = 3, step = 3) { (first, second, third) ->
                first.intersect(second).intersect(third).first()
            }
            .sumOf { itemPriorities[it]!! }

}

Compiled from "Day03.kt"
public final class day03.Day03Kt {
  private static final java.util.Map<java.lang.Character, java.lang.Integer> itemPriorities;

  public static final java.util.Map access$getItemPriorities$p();
    Code:
       0: getstatic     #10                 // Field itemPriorities:Ljava/util/Map;
       3: areturn

  static {};
    Code:
       0: new           #14                 // class kotlin/ranges/CharRange
       3: dup
       4: bipush        97
       6: bipush        122
       8: invokespecial #18                 // Method kotlin/ranges/CharRange."<init>":(CC)V
      11: checkcast     #20                 // class java/lang/Iterable
      14: new           #14                 // class kotlin/ranges/CharRange
      17: dup
      18: bipush        65
      20: bipush        90
      22: invokespecial #18                 // Method kotlin/ranges/CharRange."<init>":(CC)V
      25: checkcast     #20                 // class java/lang/Iterable
      28: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
      31: checkcast     #20                 // class java/lang/Iterable
      34: astore_0
      35: iconst_0
      36: istore_1
      37: aload_0
      38: astore_2
      39: new           #28                 // class java/util/ArrayList
      42: dup
      43: aload_0
      44: bipush        10
      46: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      49: invokespecial #35                 // Method java/util/ArrayList."<init>":(I)V
      52: checkcast     #37                 // class java/util/Collection
      55: astore_3
      56: iconst_0
      57: istore        4
      59: iconst_0
      60: istore        5
      62: aload_2
      63: invokeinterface #41,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      68: astore        6
      70: aload         6
      72: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          151
      80: aload         6
      82: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: astore        7
      89: aload_3
      90: iload         5
      92: iinc          5, 1
      95: istore        8
      97: iload         8
      99: ifge          105
     102: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     105: iload         8
     107: aload         7
     109: checkcast     #56                 // class java/lang/Character
     112: invokevirtual #60                 // Method java/lang/Character.charValue:()C
     115: istore        9
     117: istore        10
     119: astore        12
     121: iconst_0
     122: istore        11
     124: iload         9
     126: invokestatic  #64                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     129: iload         10
     131: iconst_1
     132: iadd
     133: invokestatic  #69                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     136: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     139: aload         12
     141: swap
     142: invokeinterface #79,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     147: pop
     148: goto          70
     151: aload_3
     152: checkcast     #81                 // class java/util/List
     155: nop
     156: checkcast     #20                 // class java/lang/Iterable
     159: invokestatic  #87                 // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     162: putstatic     #10                 // Field itemPriorities:Ljava/util/Map;
     165: return
}

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

  public final java.util.List<kotlin.Pair<java.util.Set<java.lang.Character>, java.util.Set<java.lang.Character>>> parse(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/CharSequence
      10: invokestatic  #30                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      13: checkcast     #32                 // class java/lang/Iterable
      16: astore_2
      17: iconst_0
      18: istore_3
      19: aload_2
      20: astore        4
      22: new           #34                 // class java/util/ArrayList
      25: dup
      26: aload_2
      27: bipush        10
      29: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #45                 // class java/util/Collection
      38: astore        5
      40: iconst_0
      41: istore        6
      43: aload         4
      45: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        7
      52: aload         7
      54: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          154
      62: aload         7
      64: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        8
      71: aload         5
      73: aload         8
      75: checkcast     #61                 // class java/lang/String
      78: astore        9
      80: astore        11
      82: iconst_0
      83: istore        10
      85: new           #63                 // class kotlin/Pair
      88: dup
      89: aload         9
      91: iconst_0
      92: aload         9
      94: invokevirtual #67                 // Method java/lang/String.length:()I
      97: iconst_2
      98: idiv
      99: invokevirtual #71                 // Method java/lang/String.substring:(II)Ljava/lang/String;
     102: dup
     103: ldc           #73                 // String substring(...)
     105: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     108: checkcast     #24                 // class java/lang/CharSequence
     111: invokestatic  #80                 // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     114: aload         9
     116: aload         9
     118: invokevirtual #67                 // Method java/lang/String.length:()I
     121: iconst_2
     122: idiv
     123: invokevirtual #83                 // Method java/lang/String.substring:(I)Ljava/lang/String;
     126: dup
     127: ldc           #73                 // String substring(...)
     129: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     132: checkcast     #24                 // class java/lang/CharSequence
     135: invokestatic  #80                 // Method kotlin/text/StringsKt.toSet:(Ljava/lang/CharSequence;)Ljava/util/Set;
     138: invokespecial #86                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     141: nop
     142: aload         11
     144: swap
     145: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     150: pop
     151: goto          52
     154: aload         5
     156: checkcast     #92                 // class java/util/List
     159: nop
     160: areturn

  public final int part1(java.util.List<? extends kotlin.Pair<? extends java.util.Set<java.lang.Character>, ? extends java.util.Set<java.lang.Character>>>);
    Code:
       0: aload_1
       1: ldc           #110                // String parsed
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #32                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #34                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #45                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          139
      56: aload         7
      58: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #63                 // class kotlin/Pair
      72: astore        9
      74: astore        13
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokevirtual #113                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      84: checkcast     #115                // class java/util/Set
      87: astore        11
      89: aload         9
      91: invokevirtual #118                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      94: checkcast     #115                // class java/util/Set
      97: astore        12
      99: aload         11
     101: checkcast     #32                 // class java/lang/Iterable
     104: aload         12
     106: checkcast     #32                 // class java/lang/Iterable
     109: invokestatic  #122                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     112: checkcast     #32                 // class java/lang/Iterable
     115: invokestatic  #126                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
     118: checkcast     #128                // class java/lang/Character
     121: invokevirtual #132                // Method java/lang/Character.charValue:()C
     124: invokestatic  #136                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     127: aload         13
     129: swap
     130: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          46
     139: aload         5
     141: checkcast     #92                 // class java/util/List
     144: nop
     145: checkcast     #32                 // class java/lang/Iterable
     148: astore_2
     149: iconst_0
     150: istore_3
     151: aload_2
     152: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     157: astore        4
     159: aload         4
     161: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     166: ifeq          228
     169: aload         4
     171: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     176: astore        5
     178: iload_3
     179: aload         5
     181: checkcast     #128                // class java/lang/Character
     184: invokevirtual #132                // Method java/lang/Character.charValue:()C
     187: istore        6
     189: istore        13
     191: iconst_0
     192: istore        7
     194: invokestatic  #142                // Method day03/Day03Kt.access$getItemPriorities$p:()Ljava/util/Map;
     197: iload         6
     199: invokestatic  #136                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     202: invokeinterface #148,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     207: dup
     208: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     211: checkcast     #154                // class java/lang/Number
     214: invokevirtual #157                // Method java/lang/Number.intValue:()I
     217: istore        14
     219: iload         13
     221: iload         14
     223: iadd
     224: istore_3
     225: goto          159
     228: iload_3
     229: ireturn

  public final int part2(java.util.List<? extends kotlin.Pair<? extends java.util.Set<java.lang.Character>, ? extends java.util.Set<java.lang.Character>>>);
    Code:
       0: aload_1
       1: ldc           #110                // String parsed
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #32                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #34                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #43                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #45                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          110
      56: aload         7
      58: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #63                 // class kotlin/Pair
      72: astore        9
      74: astore        11
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokevirtual #168                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      84: checkcast     #115                // class java/util/Set
      87: aload         9
      89: invokevirtual #171                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      92: checkcast     #32                 // class java/lang/Iterable
      95: invokestatic  #177                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
      98: aload         11
     100: swap
     101: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: goto          46
     110: aload         5
     112: checkcast     #92                 // class java/util/List
     115: nop
     116: checkcast     #32                 // class java/lang/Iterable
     119: iconst_3
     120: iconst_3
     121: iconst_0
     122: invokedynamic #196,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     127: iconst_4
     128: aconst_null
     129: invokestatic  #200                // Method kotlin/collections/CollectionsKt.windowed$default:(Ljava/lang/Iterable;IIZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/util/List;
     132: checkcast     #32                 // class java/lang/Iterable
     135: astore_2
     136: iconst_0
     137: istore_3
     138: aload_2
     139: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     144: astore        4
     146: aload         4
     148: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     153: ifeq          215
     156: aload         4
     158: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     163: astore        5
     165: iload_3
     166: aload         5
     168: checkcast     #128                // class java/lang/Character
     171: invokevirtual #132                // Method java/lang/Character.charValue:()C
     174: istore        6
     176: istore        11
     178: iconst_0
     179: istore        7
     181: invokestatic  #142                // Method day03/Day03Kt.access$getItemPriorities$p:()Ljava/util/Map;
     184: iload         6
     186: invokestatic  #136                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     189: invokeinterface #148,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     194: dup
     195: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     198: checkcast     #154                // class java/lang/Number
     201: invokevirtual #157                // Method java/lang/Number.intValue:()I
     204: istore        12
     206: iload         11
     208: iload         12
     210: iadd
     211: istore_3
     212: goto          146
     215: iload_3
     216: ireturn

  private static final char part2$lambda$4(java.util.List);
    Code:
       0: aload_0
       1: ldc           #205                // String <destruct>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: invokeinterface #208,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #115                // class java/util/Set
      16: astore_1
      17: aload_0
      18: iconst_1
      19: invokeinterface #208,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      24: checkcast     #115                // class java/util/Set
      27: astore_2
      28: aload_0
      29: iconst_2
      30: invokeinterface #208,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #115                // class java/util/Set
      38: astore_3
      39: aload_1
      40: checkcast     #32                 // class java/lang/Iterable
      43: aload_2
      44: checkcast     #32                 // class java/lang/Iterable
      47: invokestatic  #122                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      50: checkcast     #32                 // class java/lang/Iterable
      53: aload_3
      54: checkcast     #32                 // class java/lang/Iterable
      57: invokestatic  #122                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
      60: checkcast     #32                 // class java/lang/Iterable
      63: invokestatic  #126                // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
      66: checkcast     #128                // class java/lang/Character
      69: invokevirtual #132                // Method java/lang/Character.charValue:()C
      72: ireturn
}