package day05

import java.io.File

fun main() {
    val lines: List<Line> = File("src/main/kotlin/day05/day05-input.txt")
        .readLines()
        .map { it.split(" -> ") }
        .map { Line(it.first().asPoint(), it.last().asPoint()) }

    println("Part 1: " + countOverlappingPoints(lines.filter { it.isHorizontal() || it.isVertical() }))
    println("Part 2: " + countOverlappingPoints(lines))
}

fun countOverlappingPoints(lines: List<Line>): Int {
    val grid = mutableMapOf<Point, Int>()

    lines.forEach { line ->
            line.points().forEach { point ->
                grid.compute(point) { _, value ->
                    if (value == null) 1 else value + 1
                }
            }
        }

    return grid.filter { it.value >= 2 }.count()
}

fun String.asPoint(): Point =
    split(",").map { it.toInt() }.let { Point(it.first(), it.last()) }

data class Point(val x: Int, val y: Int)

data class Line(val first: Point, val last: Point) {

    fun isHorizontal(): Boolean = first.x == last.x
    fun isVertical(): Boolean = first.y == last.y

    fun points(): Sequence<Point> {
        val dx = (last.x - first.x).coerceIn(-1, 1)
        val dy = (last.y - first.y).coerceIn(-1, 1)

        return sequence {
            var point = first
            yield(point)

            while (point != last) {
                point = Point(point.x + dx, point.y + dy)
                yield(point)
            }
        }
    }
}

Compiled from "Day05.kt"
public final class day05.Day05Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/kotlin/day05/day05-input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #22                 // class java/lang/Iterable
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #24                 // class java/util/ArrayList
      27: dup
      28: aload_1
      29: bipush        10
      31: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #35                 // class java/util/Collection
      40: astore        4
      42: iconst_0
      43: istore        5
      45: aload_3
      46: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        6
      53: aload         6
      55: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          125
      63: aload         6
      65: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        7
      72: aload         4
      74: aload         7
      76: checkcast     #51                 // class java/lang/String
      79: astore        8
      81: astore        11
      83: iconst_0
      84: istore        9
      86: aload         8
      88: checkcast     #53                 // class java/lang/CharSequence
      91: iconst_1
      92: anewarray     #51                 // class java/lang/String
      95: astore        10
      97: aload         10
      99: iconst_0
     100: ldc           #55                 // String  ->
     102: aastore
     103: aload         10
     105: iconst_0
     106: iconst_0
     107: bipush        6
     109: aconst_null
     110: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     113: aload         11
     115: swap
     116: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     121: pop
     122: goto          53
     125: aload         4
     127: checkcast     #67                 // class java/util/List
     130: nop
     131: checkcast     #22                 // class java/lang/Iterable
     134: astore_1
     135: nop
     136: iconst_0
     137: istore_2
     138: aload_1
     139: astore_3
     140: new           #24                 // class java/util/ArrayList
     143: dup
     144: aload_1
     145: bipush        10
     147: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     150: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #35                 // class java/util/Collection
     156: astore        4
     158: iconst_0
     159: istore        5
     161: aload_3
     162: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     167: astore        6
     169: aload         6
     171: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     176: ifeq          243
     179: aload         6
     181: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     186: astore        7
     188: aload         4
     190: aload         7
     192: checkcast     #67                 // class java/util/List
     195: astore        8
     197: astore        11
     199: iconst_0
     200: istore        9
     202: new           #69                 // class day05/Line
     205: dup
     206: aload         8
     208: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     211: checkcast     #51                 // class java/lang/String
     214: invokestatic  #77                 // Method asPoint:(Ljava/lang/String;)Lday05/Point;
     217: aload         8
     219: invokestatic  #80                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     222: checkcast     #51                 // class java/lang/String
     225: invokestatic  #77                 // Method asPoint:(Ljava/lang/String;)Lday05/Point;
     228: invokespecial #83                 // Method day05/Line."<init>":(Lday05/Point;Lday05/Point;)V
     231: aload         11
     233: swap
     234: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     239: pop
     240: goto          169
     243: aload         4
     245: checkcast     #67                 // class java/util/List
     248: nop
     249: astore_0
     250: new           #85                 // class java/lang/StringBuilder
     253: dup
     254: invokespecial #87                 // Method java/lang/StringBuilder."<init>":()V
     257: ldc           #89                 // String Part 1:
     259: invokevirtual #93                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     262: aload_0
     263: checkcast     #22                 // class java/lang/Iterable
     266: astore_1
     267: astore        11
     269: iconst_0
     270: istore_2
     271: aload_1
     272: astore_3
     273: new           #24                 // class java/util/ArrayList
     276: dup
     277: invokespecial #94                 // Method java/util/ArrayList."<init>":()V
     280: checkcast     #35                 // class java/util/Collection
     283: astore        4
     285: iconst_0
     286: istore        5
     288: aload_3
     289: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     294: astore        6
     296: aload         6
     298: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     303: ifeq          362
     306: aload         6
     308: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     313: astore        7
     315: aload         7
     317: checkcast     #69                 // class day05/Line
     320: astore        8
     322: iconst_0
     323: istore        9
     325: aload         8
     327: invokevirtual #97                 // Method day05/Line.isHorizontal:()Z
     330: ifne          341
     333: aload         8
     335: invokevirtual #100                // Method day05/Line.isVertical:()Z
     338: ifeq          345
     341: iconst_1
     342: goto          346
     345: iconst_0
     346: ifeq          296
     349: aload         4
     351: aload         7
     353: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     358: pop
     359: goto          296
     362: aload         4
     364: checkcast     #67                 // class java/util/List
     367: nop
     368: aload         11
     370: swap
     371: invokestatic  #104                // Method countOverlappingPoints:(Ljava/util/List;)I
     374: invokevirtual #107                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     377: invokevirtual #111                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     380: getstatic     #117                // Field java/lang/System.out:Ljava/io/PrintStream;
     383: swap
     384: invokevirtual #123                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     387: new           #85                 // class java/lang/StringBuilder
     390: dup
     391: invokespecial #87                 // Method java/lang/StringBuilder."<init>":()V
     394: ldc           #125                // String Part 2:
     396: invokevirtual #93                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     399: aload_0
     400: invokestatic  #104                // Method countOverlappingPoints:(Ljava/util/List;)I
     403: invokevirtual #107                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     406: invokevirtual #111                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     409: getstatic     #117                // Field java/lang/System.out:Ljava/io/PrintStream;
     412: swap
     413: invokevirtual #123                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     416: return

  public static final int countOverlappingPoints(java.util.List<day05.Line>);
    Code:
       0: aload_0
       1: ldc           #151                // String lines
       3: invokestatic  #157                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #159                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #160                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #162                // class java/util/Map
      16: astore_1
      17: aload_0
      18: checkcast     #22                 // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        4
      32: aload         4
      34: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          139
      42: aload         4
      44: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        5
      51: aload         5
      53: checkcast     #69                 // class day05/Line
      56: astore        6
      58: iconst_0
      59: istore        7
      61: aload         6
      63: invokevirtual #166                // Method day05/Line.points:()Lkotlin/sequences/Sequence;
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokeinterface #169,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      78: astore        10
      80: aload         10
      82: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          133
      90: aload         10
      92: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      97: astore        11
      99: aload         11
     101: checkcast     #171                // class day05/Point
     104: astore        12
     106: iconst_0
     107: istore        13
     109: aload_1
     110: aload         12
     112: invokedynamic #190,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
     117: invokedynamic #201,  0            // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     122: invokeinterface #205,  3          // InterfaceMethod java/util/Map.compute:(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     127: pop
     128: nop
     129: nop
     130: goto          80
     133: nop
     134: nop
     135: nop
     136: goto          32
     139: nop
     140: aload_1
     141: astore_2
     142: iconst_0
     143: istore_3
     144: aload_2
     145: astore        4
     147: new           #159                // class java/util/LinkedHashMap
     150: dup
     151: invokespecial #160                // Method java/util/LinkedHashMap."<init>":()V
     154: checkcast     #162                // class java/util/Map
     157: astore        5
     159: iconst_0
     160: istore        6
     162: aload         4
     164: invokeinterface #209,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     169: invokeinterface #212,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     174: astore        7
     176: aload         7
     178: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     183: ifeq          255
     186: aload         7
     188: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     193: checkcast     #214                // class java/util/Map$Entry
     196: astore        8
     198: aload         8
     200: astore        9
     202: iconst_0
     203: istore        10
     205: aload         9
     207: invokeinterface #217,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     212: checkcast     #219                // class java/lang/Number
     215: invokevirtual #223                // Method java/lang/Number.intValue:()I
     218: iconst_2
     219: if_icmplt     226
     222: iconst_1
     223: goto          227
     226: iconst_0
     227: ifeq          176
     230: aload         5
     232: aload         8
     234: invokeinterface #226,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     239: aload         8
     241: invokeinterface #217,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     246: invokeinterface #229,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     251: pop
     252: goto          176
     255: aload         5
     257: nop
     258: invokeinterface #232,  1          // InterfaceMethod java/util/Map.size:()I
     263: ireturn

  public static final day05.Point asPoint(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #247                // String <this>
       3: invokestatic  #157                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #53                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #51                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #249                // String ,
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #22                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #24                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #35                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #51                 // class java/lang/String
      92: astore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #255                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #259                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         10
     110: swap
     111: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #67                 // class java/util/List
     125: nop
     126: astore_2
     127: iconst_0
     128: istore_3
     129: new           #171                // class day05/Point
     132: dup
     133: aload_2
     134: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     137: checkcast     #219                // class java/lang/Number
     140: invokevirtual #223                // Method java/lang/Number.intValue:()I
     143: aload_2
     144: invokestatic  #80                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     147: checkcast     #219                // class java/lang/Number
     150: invokevirtual #223                // Method java/lang/Number.intValue:()I
     153: invokespecial #262                // Method day05/Point."<init>":(II)V
     156: nop
     157: areturn

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

  private static final java.lang.Integer countOverlappingPoints$lambda$6$lambda$5$lambda$3(day05.Point, java.lang.Integer);
    Code:
       0: aload_0
       1: ldc_w         #272                // String <unused var>
       4: invokestatic  #157                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: dup
       9: ifnonnull     20
      12: pop
      13: iconst_1
      14: invokestatic  #259                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: goto          28
      20: invokevirtual #273                // Method java/lang/Integer.intValue:()I
      23: iconst_1
      24: iadd
      25: invokestatic  #259                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: areturn

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


package com.chimber.debtislav.util

data class Edge<T>(val a: T, val b: T, var weight: Int)

class Graph<T>(edgesList: List<Edge<T>>) {
    val edges: MutableList<Edge<T>>
    private var start: T? = null

    init {
        val edgeMap = HashMap<Pair<T, T>, Int>()
        for (edge in edgesList) {
            edgeMap.compute(edge.a to edge.b) { _, v -> edge.weight + (v ?: 0) }
        }
        edges = edgeMap.map { Edge(it.key.first, it.key.second, it.value) }.toMutableList()
    }

    private fun dfs(v: T, g: Map<T, List<Edge<T>>>, used: MutableMap<T, Int>): MutableList<Edge<T>>? {
        used[v] = 1
        val outEdges = g[v] ?: run {
            used[v] = 2
            return null
        }
        for (edge in outEdges) {
            val x = edge.b
            if (used[x] == 0) {
                val cycle = dfs(x, g, used)
                cycle?.let {
                    if (start == null) return it
                    else if (start == v) start = null
                    it.add(edge)
                    return it
                }
            } else if (used[x] == 1) {
                start = x
                return mutableListOf(edge)
            }
        }
        used[v] = 2
        return null
    }

    private fun findCycle(): List<Edge<T>> {
        val g = mutableMapOf<T, MutableList<Edge<T>>>()
        for (edge in edges) {
            if (!g.contains(edge.a)) {
                g[edge.a] = mutableListOf()
            }
            g[edge.a]?.add(edge)
        }
        val vertices = edges.map { listOf(it.a, it.b) }.flatten().distinct()

        val used = vertices.associateWith { 0 }.toMutableMap()
        start = null
        for (v in vertices) {
            if (used[v] == 0) {
                val cycle = dfs(v, g, used)
                if (cycle != null) {
                    return cycle.reversed()
                }
            }
        }
        return emptyList()
    }

    private fun reduceCycle(): Boolean {
        val cycle = findCycle()
        val minWeight = cycle.minByOrNull { it.weight }?.weight ?: return false
        val edgesToRemove = mutableListOf<Edge<T>>()
        for (edge in cycle) {
            edge.weight -= minWeight
            if (edge.weight == 0) {
                edgesToRemove.add(edge)
            }
        }
        edges.removeAll(edgesToRemove)
        return true
    }

    fun reduceAllCycles() {
        var finished = false
        while (!finished) {
            finished = !reduceCycle()
        }
    }
}

Compiled from "Graph.kt"
public final class com.chimber.debtislav.util.Graph<T> {
  private final java.util.List<com.chimber.debtislav.util.Edge<T>> edges;

  private T start;

  public com.chimber.debtislav.util.Graph(java.util.List<com.chimber.debtislav.util.Edge<T>>);
    Code:
       0: aload_1
       1: ldc           #11                 // String edgesList
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #20                 // Method java/lang/Object."<init>":()V
      10: nop
      11: new           #22                 // class java/util/HashMap
      14: dup
      15: invokespecial #23                 // Method java/util/HashMap."<init>":()V
      18: astore_2
      19: aload_1
      20: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      25: astore_3
      26: aload_3
      27: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      32: ifeq          79
      35: aload_3
      36: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: checkcast     #41                 // class com/chimber/debtislav/util/Edge
      44: astore        4
      46: aload_2
      47: aload         4
      49: invokevirtual #44                 // Method com/chimber/debtislav/util/Edge.getA:()Ljava/lang/Object;
      52: aload         4
      54: invokevirtual #47                 // Method com/chimber/debtislav/util/Edge.getB:()Ljava/lang/Object;
      57: invokestatic  #53                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      60: aload         4
      62: invokedynamic #73,  0             // InvokeDynamic #0:invoke:(Lcom/chimber/debtislav/util/Edge;)Lkotlin/jvm/functions/Function2;
      67: invokedynamic #84,  0             // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
      72: invokevirtual #88                 // Method java/util/HashMap.compute:(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
      75: pop
      76: goto          26
      79: aload_0
      80: aload_2
      81: checkcast     #90                 // class java/util/Map
      84: astore_3
      85: astore        12
      87: iconst_0
      88: istore        4
      90: aload_3
      91: astore        5
      93: new           #92                 // class java/util/ArrayList
      96: dup
      97: aload_3
      98: invokeinterface #96,  1           // InterfaceMethod java/util/Map.size:()I
     103: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
     106: checkcast     #101                // class java/util/Collection
     109: astore        6
     111: iconst_0
     112: istore        7
     114: aload         5
     116: invokeinterface #105,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     121: invokeinterface #108,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     126: astore        8
     128: aload         8
     130: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     135: ifeq          219
     138: aload         8
     140: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     145: checkcast     #110                // class java/util/Map$Entry
     148: astore        9
     150: aload         6
     152: aload         9
     154: astore        10
     156: astore        13
     158: iconst_0
     159: istore        11
     161: new           #41                 // class com/chimber/debtislav/util/Edge
     164: dup
     165: aload         10
     167: invokeinterface #113,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     172: checkcast     #115                // class kotlin/Pair
     175: invokevirtual #118                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     178: aload         10
     180: invokeinterface #113,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     185: checkcast     #115                // class kotlin/Pair
     188: invokevirtual #121                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     191: aload         10
     193: invokeinterface #124,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     198: checkcast     #126                // class java/lang/Number
     201: invokevirtual #129                // Method java/lang/Number.intValue:()I
     204: invokespecial #132                // Method com/chimber/debtislav/util/Edge."<init>":(Ljava/lang/Object;Ljava/lang/Object;I)V
     207: aload         13
     209: swap
     210: invokeinterface #136,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     215: pop
     216: goto          128
     219: aload         6
     221: checkcast     #25                 // class java/util/List
     224: nop
     225: aload         12
     227: swap
     228: checkcast     #101                // class java/util/Collection
     231: invokestatic  #142                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     234: putfield      #146                // Field edges:Ljava/util/List;
     237: nop
     238: return

  public final java.util.List<com.chimber.debtislav.util.Edge<T>> getEdges();
    Code:
       0: aload_0
       1: getfield      #146                // Field edges:Ljava/util/List;
       4: areturn

  private final java.util.List<com.chimber.debtislav.util.Edge<T>> dfs(T, java.util.Map<T, ? extends java.util.List<com.chimber.debtislav.util.Edge<T>>>, java.util.Map<T, java.lang.Integer>);
    Code:
       0: aload_3
       1: aload_1
       2: iconst_1
       3: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: invokeinterface #179,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      11: pop
      12: aload_2
      13: aload_1
      14: invokeinterface #183,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      19: checkcast     #25                 // class java/util/List
      22: dup
      23: ifnonnull     50
      26: pop
      27: aload_0
      28: checkcast     #2                  // class com/chimber/debtislav/util/Graph
      31: astore        7
      33: iconst_0
      34: istore        8
      36: aload_3
      37: aload_1
      38: iconst_2
      39: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      42: invokeinterface #179,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      47: pop
      48: aconst_null
      49: areturn
      50: astore        4
      52: aload         4
      54: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      59: astore        5
      61: aload         5
      63: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          230
      71: aload         5
      73: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: checkcast     #41                 // class com/chimber/debtislav/util/Edge
      81: astore        6
      83: aload         6
      85: invokevirtual #47                 // Method com/chimber/debtislav/util/Edge.getB:()Ljava/lang/Object;
      88: astore        7
      90: aload_3
      91: aload         7
      93: invokeinterface #183,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      98: checkcast     #172                // class java/lang/Integer
     101: dup
     102: ifnonnull     109
     105: pop
     106: goto          176
     109: invokevirtual #184                // Method java/lang/Integer.intValue:()I
     112: ifne          176
     115: aload_0
     116: aload         7
     118: aload_2
     119: aload_3
     120: invokespecial #186                // Method dfs:(Ljava/lang/Object;Ljava/util/Map;Ljava/util/Map;)Ljava/util/List;
     123: astore        8
     125: aload         8
     127: ifnull        61
     130: aload         8
     132: astore        9
     134: iconst_0
     135: istore        10
     137: aload_0
     138: getfield      #190                // Field start:Ljava/lang/Object;
     141: ifnonnull     147
     144: aload         9
     146: areturn
     147: aload_0
     148: getfield      #190                // Field start:Ljava/lang/Object;
     151: aload_1
     152: invokestatic  #194                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     155: ifeq          163
     158: aload_0
     159: aconst_null
     160: putfield      #190                // Field start:Ljava/lang/Object;
     163: aload         9
     165: aload         6
     167: invokeinterface #195,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     172: pop
     173: aload         9
     175: areturn
     176: aload_3
     177: aload         7
     179: invokeinterface #183,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     184: checkcast     #172                // class java/lang/Integer
     187: iconst_1
     188: istore        8
     190: dup
     191: ifnonnull     198
     194: pop
     195: goto          61
     198: invokevirtual #184                // Method java/lang/Integer.intValue:()I
     201: iload         8
     203: if_icmpne     61
     206: aload_0
     207: aload         7
     209: putfield      #190                // Field start:Ljava/lang/Object;
     212: iconst_1
     213: anewarray     #41                 // class com/chimber/debtislav/util/Edge
     216: astore        8
     218: aload         8
     220: iconst_0
     221: aload         6
     223: aastore
     224: aload         8
     226: invokestatic  #199                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     229: areturn
     230: aload_3
     231: aload_1
     232: iconst_2
     233: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     236: invokeinterface #179,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     241: pop
     242: aconst_null
     243: areturn

  private final java.util.List<com.chimber.debtislav.util.Edge<T>> findCycle();
    Code:
       0: new           #211                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #212                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #90                 // class java/util/Map
      10: astore_1
      11: aload_0
      12: getfield      #146                // Field edges:Ljava/util/List;
      15: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      20: astore_2
      21: aload_2
      22: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          106
      30: aload_2
      31: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      36: checkcast     #41                 // class com/chimber/debtislav/util/Edge
      39: astore_3
      40: aload_1
      41: aload_3
      42: invokevirtual #44                 // Method com/chimber/debtislav/util/Edge.getA:()Ljava/lang/Object;
      45: invokeinterface #215,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      50: ifne          75
      53: nop
      54: aload_1
      55: aload_3
      56: invokevirtual #44                 // Method com/chimber/debtislav/util/Edge.getA:()Ljava/lang/Object;
      59: new           #92                 // class java/util/ArrayList
      62: dup
      63: invokespecial #216                // Method java/util/ArrayList."<init>":()V
      66: checkcast     #25                 // class java/util/List
      69: invokeinterface #179,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      74: pop
      75: aload_1
      76: aload_3
      77: invokevirtual #44                 // Method com/chimber/debtislav/util/Edge.getA:()Ljava/lang/Object;
      80: invokeinterface #183,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      85: checkcast     #25                 // class java/util/List
      88: dup
      89: ifnull        102
      92: aload_3
      93: invokeinterface #195,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          21
     102: pop
     103: goto          21
     106: aload_0
     107: getfield      #146                // Field edges:Ljava/util/List;
     110: checkcast     #218                // class java/lang/Iterable
     113: astore_3
     114: iconst_0
     115: istore        4
     117: aload_3
     118: astore        5
     120: new           #92                 // class java/util/ArrayList
     123: dup
     124: aload_3
     125: bipush        10
     127: invokestatic  #222                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     130: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
     133: checkcast     #101                // class java/util/Collection
     136: astore        6
     138: iconst_0
     139: istore        7
     141: aload         5
     143: invokeinterface #223,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     148: astore        8
     150: aload         8
     152: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     157: ifeq          224
     160: aload         8
     162: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     167: astore        9
     169: aload         6
     171: aload         9
     173: checkcast     #41                 // class com/chimber/debtislav/util/Edge
     176: astore        10
     178: astore        13
     180: iconst_0
     181: istore        11
     183: iconst_2
     184: anewarray     #5                  // class java/lang/Object
     187: astore        12
     189: aload         12
     191: iconst_0
     192: aload         10
     194: invokevirtual #44                 // Method com/chimber/debtislav/util/Edge.getA:()Ljava/lang/Object;
     197: aastore
     198: aload         12
     200: iconst_1
     201: aload         10
     203: invokevirtual #47                 // Method com/chimber/debtislav/util/Edge.getB:()Ljava/lang/Object;
     206: aastore
     207: aload         12
     209: invokestatic  #226                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     212: aload         13
     214: swap
     215: invokeinterface #136,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     220: pop
     221: goto          150
     224: aload         6
     226: checkcast     #25                 // class java/util/List
     229: nop
     230: checkcast     #218                // class java/lang/Iterable
     233: invokestatic  #230                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     236: checkcast     #218                // class java/lang/Iterable
     239: invokestatic  #233                // Method kotlin/collections/CollectionsKt.distinct:(Ljava/lang/Iterable;)Ljava/util/List;
     242: astore_2
     243: aload_2
     244: checkcast     #218                // class java/lang/Iterable
     247: astore        4
     249: iconst_0
     250: istore        5
     252: new           #211                // class java/util/LinkedHashMap
     255: dup
     256: aload         4
     258: bipush        10
     260: invokestatic  #222                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     263: invokestatic  #239                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     266: bipush        16
     268: invokestatic  #245                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     271: invokespecial #246                // Method java/util/LinkedHashMap."<init>":(I)V
     274: astore        6
     276: aload         4
     278: astore        7
     280: iconst_0
     281: istore        8
     283: aload         7
     285: invokeinterface #223,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     290: astore        9
     292: aload         9
     294: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     299: ifeq          350
     302: aload         9
     304: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     309: astore        10
     311: aload         6
     313: checkcast     #90                 // class java/util/Map
     316: aload         10
     318: aload         10
     320: astore        11
     322: astore        14
     324: astore        13
     326: iconst_0
     327: istore        12
     329: iconst_0
     330: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     333: astore        15
     335: aload         13
     337: aload         14
     339: aload         15
     341: invokeinterface #179,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     346: pop
     347: goto          292
     350: aload         6
     352: checkcast     #90                 // class java/util/Map
     355: nop
     356: invokestatic  #250                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     359: astore_3
     360: aload_0
     361: aconst_null
     362: putfield      #190                // Field start:Ljava/lang/Object;
     365: aload_2
     366: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     371: astore        4
     373: aload         4
     375: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     380: ifeq          441
     383: aload         4
     385: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     390: astore        5
     392: aload_3
     393: aload         5
     395: invokeinterface #183,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     400: checkcast     #172                // class java/lang/Integer
     403: dup
     404: ifnonnull     411
     407: pop
     408: goto          373
     411: invokevirtual #184                // Method java/lang/Integer.intValue:()I
     414: ifne          373
     417: aload_0
     418: aload         5
     420: aload_1
     421: aload_3
     422: invokespecial #186                // Method dfs:(Ljava/lang/Object;Ljava/util/Map;Ljava/util/Map;)Ljava/util/List;
     425: astore        6
     427: aload         6
     429: ifnull        373
     432: aload         6
     434: checkcast     #218                // class java/lang/Iterable
     437: invokestatic  #253                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     440: areturn
     441: invokestatic  #256                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     444: areturn

  private final boolean reduceCycle();
    Code:
       0: aload_0
       1: invokespecial #270                // Method findCycle:()Ljava/util/List;
       4: astore_1
       5: aload_1
       6: checkcast     #218                // class java/lang/Iterable
       9: astore        4
      11: iconst_0
      12: istore        5
      14: aload         4
      16: invokeinterface #223,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      21: astore        6
      23: aload         6
      25: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifne          37
      33: aconst_null
      34: goto          131
      37: aload         6
      39: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: astore        7
      46: aload         6
      48: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifne          61
      56: aload         7
      58: goto          131
      61: aload         7
      63: checkcast     #41                 // class com/chimber/debtislav/util/Edge
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokevirtual #273                // Method com/chimber/debtislav/util/Edge.getWeight:()I
      76: istore        8
      78: aload         6
      80: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      85: astore        9
      87: aload         9
      89: checkcast     #41                 // class com/chimber/debtislav/util/Edge
      92: astore        10
      94: iconst_0
      95: istore        11
      97: aload         10
      99: invokevirtual #273                // Method com/chimber/debtislav/util/Edge.getWeight:()I
     102: istore        10
     104: iload         8
     106: iload         10
     108: if_icmple     119
     111: aload         9
     113: astore        7
     115: iload         10
     117: istore        8
     119: aload         6
     121: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     126: ifne          78
     129: aload         7
     131: checkcast     #41                 // class com/chimber/debtislav/util/Edge
     134: dup
     135: ifnull        144
     138: invokevirtual #273                // Method com/chimber/debtislav/util/Edge.getWeight:()I
     141: goto          147
     144: pop
     145: iconst_0
     146: ireturn
     147: istore_2
     148: new           #92                 // class java/util/ArrayList
     151: dup
     152: invokespecial #216                // Method java/util/ArrayList."<init>":()V
     155: checkcast     #25                 // class java/util/List
     158: astore_3
     159: aload_1
     160: invokeinterface #29,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     165: astore        4
     167: aload         4
     169: invokeinterface #35,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     174: ifeq          221
     177: aload         4
     179: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     184: checkcast     #41                 // class com/chimber/debtislav/util/Edge
     187: astore        5
     189: aload         5
     191: aload         5
     193: invokevirtual #273                // Method com/chimber/debtislav/util/Edge.getWeight:()I
     196: iload_2
     197: isub
     198: invokevirtual #276                // Method com/chimber/debtislav/util/Edge.setWeight:(I)V
     201: aload         5
     203: invokevirtual #273                // Method com/chimber/debtislav/util/Edge.getWeight:()I
     206: ifne          167
     209: aload_3
     210: aload         5
     212: invokeinterface #195,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     217: pop
     218: goto          167
     221: aload_0
     222: getfield      #146                // Field edges:Ljava/util/List;
     225: aload_3
     226: checkcast     #101                // class java/util/Collection
     229: invokeinterface #280,  2          // InterfaceMethod java/util/List.removeAll:(Ljava/util/Collection;)Z
     234: pop
     235: iconst_1
     236: ireturn

  public final void reduceAllCycles();
    Code:
       0: iconst_0
       1: istore_1
       2: iload_1
       3: ifne          22
       6: aload_0
       7: invokespecial #294                // Method reduceCycle:()Z
      10: ifne          17
      13: iconst_1
      14: goto          18
      17: iconst_0
      18: istore_1
      19: goto          2
      22: return

  private static final java.lang.Integer _init_$lambda$0(com.chimber.debtislav.util.Edge, kotlin.Pair, java.lang.Integer);
    Code:
       0: aload_1
       1: ldc_w         #298                // String <unused var>
       4: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #273                // Method com/chimber/debtislav/util/Edge.getWeight:()I
      11: aload_2
      12: dup
      13: ifnull        22
      16: invokevirtual #184                // Method java/lang/Integer.intValue:()I
      19: goto          24
      22: pop
      23: iconst_0
      24: iadd
      25: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: areturn

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


package dev.nycode.regenbogenice.util

import kotlin.math.min

/**
 * Calculates the string distance between source and target strings using
 * the Damerau-Levenshtein algorithm. The distance is case-sensitive.
 *
 * @param source The source String.
 * @param target The target String.
 * @return The distance between source and target strings.
 */
fun calculateDistance(source: CharSequence, target: CharSequence): Int {
    val sourceLength = source.length
    val targetLength = target.length
    if (sourceLength == 0) return targetLength
    if (targetLength == 0) return sourceLength
    val dist = Array(sourceLength + 1) { IntArray(targetLength + 1) }
    for (i in 0 until sourceLength + 1) {
        dist[i][0] = i
    }
    for (j in 0 until targetLength + 1) {
        dist[0][j] = j
    }
    for (i in 1 until sourceLength + 1) {
        for (j in 1 until targetLength + 1) {
            val cost = if (source[i - 1] == target[j - 1]) 0 else 1
            dist[i][j] = min(
                min(dist[i - 1][j] + 1, dist[i][j - 1] + 1),
                dist[i - 1][j - 1] + cost
            )
            if (i > 1 && j > 1 && source[i - 1] == target[j - 2] && source[i - 2] == target[j - 1]) {
                dist[i][j] = min(dist[i][j], dist[i - 2][j - 2] + cost)
            }
        }
    }
    return dist[sourceLength][targetLength]
}

inline fun <T> Collection<T>.minByDistanceOrNull(
    text: CharSequence,
    toString: (T) -> CharSequence = { it.toString() }
) =
    minByOrNull { calculateDistance(text, toString(it)) }

Compiled from "DamerauLevenshtein.kt"
public final class dev.nycode.regenbogenice.util.DamerauLevenshteinKt$minByDistanceOrNull$1 implements kotlin.jvm.functions.Function1<T, java.lang.String> {
  public static final dev.nycode.regenbogenice.util.DamerauLevenshteinKt$minByDistanceOrNull$1 INSTANCE;

  public dev.nycode.regenbogenice.util.DamerauLevenshteinKt$minByDistanceOrNull$1();
    Code:
       0: aload_0
       1: invokespecial #11                 // Method java/lang/Object."<init>":()V
       4: return

  public final java.lang.String invoke(T);
    Code:
       0: aload_1
       1: invokestatic  #21                 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
       4: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokevirtual #26                 // Method invoke:(Ljava/lang/Object;)Ljava/lang/String;
       5: areturn

  static {};
    Code:
       0: new           #2                  // class dev/nycode/regenbogenice/util/DamerauLevenshteinKt$minByDistanceOrNull$1
       3: dup
       4: invokespecial #29                 // Method "<init>":()V
       7: putstatic     #32                 // Field INSTANCE:Ldev/nycode/regenbogenice/util/DamerauLevenshteinKt$minByDistanceOrNull$1;
      10: return
}

Compiled from "DamerauLevenshtein.kt"
public final class dev.nycode.regenbogenice.util.DamerauLevenshteinKt {
  public static final int calculateDistance(java.lang.CharSequence, java.lang.CharSequence);
    Code:
       0: aload_0
       1: ldc           #9                  // String source
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String target
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      18: istore_2
      19: aload_1
      20: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      25: istore_3
      26: iload_2
      27: ifne          32
      30: iload_3
      31: ireturn
      32: iload_3
      33: ifne          38
      36: iload_2
      37: ireturn
      38: iconst_0
      39: istore        5
      41: iload_2
      42: iconst_1
      43: iadd
      44: istore        6
      46: iload         6
      48: anewarray     #25                 // class "[I"
      51: astore        7
      53: iload         5
      55: iload         6
      57: if_icmpge     80
      60: iload         5
      62: istore        8
      64: aload         7
      66: iload         8
      68: iload_3
      69: iconst_1
      70: iadd
      71: newarray       int
      73: aastore
      74: iinc          5, 1
      77: goto          53
      80: aload         7
      82: astore        4
      84: iconst_0
      85: istore        5
      87: iload_2
      88: iconst_1
      89: iadd
      90: istore        6
      92: iload         5
      94: iload         6
      96: if_icmpge     114
      99: aload         4
     101: iload         5
     103: aaload
     104: iconst_0
     105: iload         5
     107: iastore
     108: iinc          5, 1
     111: goto          92
     114: iconst_0
     115: istore        5
     117: iload_3
     118: iconst_1
     119: iadd
     120: istore        6
     122: iload         5
     124: iload         6
     126: if_icmpge     144
     129: aload         4
     131: iconst_0
     132: aaload
     133: iload         5
     135: iload         5
     137: iastore
     138: iinc          5, 1
     141: goto          122
     144: iconst_1
     145: istore        5
     147: iload_2
     148: iconst_1
     149: iadd
     150: istore        6
     152: iload         5
     154: iload         6
     156: if_icmpge     362
     159: iconst_1
     160: istore        7
     162: iload_3
     163: iconst_1
     164: iadd
     165: istore        8
     167: iload         7
     169: iload         8
     171: if_icmpge     356
     174: aload_0
     175: iload         5
     177: iconst_1
     178: isub
     179: invokeinterface #29,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     184: aload_1
     185: iload         7
     187: iconst_1
     188: isub
     189: invokeinterface #29,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     194: if_icmpne     201
     197: iconst_0
     198: goto          202
     201: iconst_1
     202: istore        9
     204: aload         4
     206: iload         5
     208: aaload
     209: iload         7
     211: nop
     212: aload         4
     214: iload         5
     216: iconst_1
     217: isub
     218: aaload
     219: iload         7
     221: iaload
     222: iconst_1
     223: iadd
     224: aload         4
     226: iload         5
     228: aaload
     229: iload         7
     231: iconst_1
     232: isub
     233: iaload
     234: iconst_1
     235: iadd
     236: invokestatic  #35                 // Method java/lang/Math.min:(II)I
     239: aload         4
     241: iload         5
     243: iconst_1
     244: isub
     245: aaload
     246: iload         7
     248: iconst_1
     249: isub
     250: iaload
     251: iload         9
     253: iadd
     254: invokestatic  #35                 // Method java/lang/Math.min:(II)I
     257: iastore
     258: iload         5
     260: iconst_1
     261: if_icmple     350
     264: iload         7
     266: iconst_1
     267: if_icmple     350
     270: aload_0
     271: iload         5
     273: iconst_1
     274: isub
     275: invokeinterface #29,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     280: aload_1
     281: iload         7
     283: iconst_2
     284: isub
     285: invokeinterface #29,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     290: if_icmpne     350
     293: aload_0
     294: iload         5
     296: iconst_2
     297: isub
     298: invokeinterface #29,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     303: aload_1
     304: iload         7
     306: iconst_1
     307: isub
     308: invokeinterface #29,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     313: if_icmpne     350
     316: aload         4
     318: iload         5
     320: aaload
     321: iload         7
     323: aload         4
     325: iload         5
     327: aaload
     328: iload         7
     330: iaload
     331: aload         4
     333: iload         5
     335: iconst_2
     336: isub
     337: aaload
     338: iload         7
     340: iconst_2
     341: isub
     342: iaload
     343: iload         9
     345: iadd
     346: invokestatic  #35                 // Method java/lang/Math.min:(II)I
     349: iastore
     350: iinc          7, 1
     353: goto          167
     356: iinc          5, 1
     359: goto          152
     362: aload         4
     364: iload_2
     365: aaload
     366: iload_3
     367: iaload
     368: ireturn

  public static final <T> T minByDistanceOrNull(java.util.Collection<? extends T>, java.lang.CharSequence, kotlin.jvm.functions.Function1<? super T, ? extends java.lang.CharSequence>);
    Code:
       0: aload_0
       1: ldc           #51                 // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #53                 // String text
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_2
      13: ldc           #55                 // String toString
      15: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: iconst_0
      19: istore_3
      20: aload_0
      21: checkcast     #57                 // class java/lang/Iterable
      24: astore        4
      26: iconst_0
      27: istore        5
      29: aload         4
      31: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifne          52
      48: aconst_null
      49: goto          160
      52: aload         6
      54: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         6
      63: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifne          76
      71: aload         7
      73: goto          160
      76: aload         7
      78: astore        8
      80: iconst_0
      81: istore        9
      83: aload_1
      84: aload_2
      85: aload         8
      87: invokeinterface #77,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      92: checkcast     #19                 // class java/lang/CharSequence
      95: invokestatic  #79                 // Method calculateDistance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I
      98: istore        8
     100: aload         6
     102: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     107: astore        9
     109: aload         9
     111: astore        10
     113: iconst_0
     114: istore        11
     116: aload_1
     117: aload_2
     118: aload         10
     120: invokeinterface #77,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     125: checkcast     #19                 // class java/lang/CharSequence
     128: invokestatic  #79                 // Method calculateDistance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I
     131: istore        10
     133: iload         8
     135: iload         10
     137: if_icmple     148
     140: aload         9
     142: astore        7
     144: iload         10
     146: istore        8
     148: aload         6
     150: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifne          100
     158: aload         7
     160: areturn

  public static java.lang.Object minByDistanceOrNull$default(java.util.Collection, java.lang.CharSequence, kotlin.jvm.functions.Function1, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          13
       6: getstatic     #105                // Field dev/nycode/regenbogenice/util/DamerauLevenshteinKt$minByDistanceOrNull$1.INSTANCE:Ldev/nycode/regenbogenice/util/DamerauLevenshteinKt$minByDistanceOrNull$1;
       9: checkcast     #73                 // class kotlin/jvm/functions/Function1
      12: astore_2
      13: aload_0
      14: ldc           #51                 // String <this>
      16: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      19: aload_1
      20: ldc           #53                 // String text
      22: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      25: aload_2
      26: ldc           #55                 // String toString
      28: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      31: iconst_0
      32: istore_3
      33: aload_0
      34: checkcast     #57                 // class java/lang/Iterable
      37: astore        4
      39: iconst_0
      40: istore        5
      42: aload         4
      44: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        6
      51: aload         6
      53: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifne          65
      61: aconst_null
      62: goto          173
      65: aload         6
      67: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        7
      74: aload         6
      76: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifne          89
      84: aload         7
      86: goto          173
      89: aload         7
      91: astore        8
      93: iconst_0
      94: istore        9
      96: aload_1
      97: aload_2
      98: aload         8
     100: invokeinterface #77,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     105: checkcast     #19                 // class java/lang/CharSequence
     108: invokestatic  #79                 // Method calculateDistance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I
     111: istore        8
     113: aload         6
     115: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        9
     122: aload         9
     124: astore        10
     126: iconst_0
     127: istore        11
     129: aload_1
     130: aload_2
     131: aload         10
     133: invokeinterface #77,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     138: checkcast     #19                 // class java/lang/CharSequence
     141: invokestatic  #79                 // Method calculateDistance:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)I
     144: istore        10
     146: iload         8
     148: iload         10
     150: if_icmple     161
     153: aload         9
     155: astore        7
     157: iload         10
     159: istore        8
     161: aload         6
     163: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     168: ifne          113
     171: aload         7
     173: areturn
}


package com.gitTraining

fun computeFibbonaciNumber(position: Int?, recursion: Boolean = false): Int {
    if (recursion) return recursiveFibbonachi(position!!)
    var notNullPosition = position
    if (notNullPosition == null) {
        notNullPosition = 1
    }
    if (position == 0) return 0
    if (position != null) {
        if (position < 0) {
            return computeNegativeFibbonachi(position)
        }
    }

    if (notNullPosition <= 2) return 1

    if (position == 1 || position == 2) return 1

    var smallFibbonachiNumber = 1
    var largeFibbonachiNumber = 1

    var currentPosition = 2
    while (currentPosition < position!!) {
        val nextFibbonachiNumber = smallFibbonachiNumber + largeFibbonachiNumber
        smallFibbonachiNumber = largeFibbonachiNumber
        largeFibbonachiNumber = nextFibbonachiNumber
        currentPosition ++
    }
    return largeFibbonachiNumber
}

fun computeFibbonachiArray(start: Int, end: Int, efficient: Boolean = false): List<Int> {
    if (!efficient) return (start..end).map { computeFibbonaciNumber(it) }
    if (start > end) return listOf()
    if (start == end) return listOf(computeFibbonaciNumber(start))
    val output = mutableListOf(computeFibbonaciNumber(start), computeFibbonaciNumber(start + 1))
    (2..(end - start)).forEach { output.add(output[it - 2] + output[it - 1]) }
    return output
}
fun recursiveFibbonachi(previous: Int, current: Int, stepsLeft: Int): Int {
    if (stepsLeft < 0) return 1
    return when (stepsLeft) {
        0 -> current
        else -> recursiveFibbonachi(current, previous + current, stepsLeft - 1)
    }
}
fun computeNegativeFibbonachi(position:Int): Int {
    if (position >= 0) throw Exception("potition must be smaller than zero!")
    val resultIsNegative = position % 2 == 0
    val absoluteResult = computeFibbonaciNumber(-position)
    return if (resultIsNegative) (absoluteResult * -1) else absoluteResult
}

fun recursiveFibbonachi(initialPosition: Int, left: Int = 0, right: Int = 1, position: Int = initialPosition): Int {
    if (initialPosition == 0) return 0
    if (position == 0) return left
    if (initialPosition > 0) {
        return recursiveFibbonachi(initialPosition, right, left + right, position - 1)
    } else {
        return recursiveFibbonachi(initialPosition, right - left, left, position + 1)
    }
}

Compiled from "Fibbonaci.kt"
public final class com.gitTraining.FibbonaciKt {
  public static final int computeFibbonaciNumber(java.lang.Integer, boolean);
    Code:
       0: iload_1
       1: ifeq          22
       4: aload_0
       5: dup
       6: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       9: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
      12: iconst_0
      13: iconst_0
      14: iconst_0
      15: bipush        14
      17: aconst_null
      18: invokestatic  #23                 // Method recursiveFibbonachi$default:(IIIIILjava/lang/Object;)I
      21: ireturn
      22: aload_0
      23: astore_2
      24: aload_2
      25: ifnonnull     33
      28: iconst_1
      29: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: astore_2
      33: aload_0
      34: dup
      35: ifnonnull     42
      38: pop
      39: goto          50
      42: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
      45: ifne          50
      48: iconst_0
      49: ireturn
      50: aload_0
      51: ifnull        69
      54: aload_0
      55: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
      58: ifge          69
      61: aload_0
      62: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
      65: invokestatic  #31                 // Method computeNegativeFibbonachi:(I)I
      68: ireturn
      69: aload_2
      70: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
      73: iconst_2
      74: if_icmpgt     79
      77: iconst_1
      78: ireturn
      79: aload_0
      80: iconst_1
      81: istore_3
      82: dup
      83: ifnonnull     90
      86: pop
      87: goto          97
      90: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
      93: iload_3
      94: if_icmpeq     115
      97: aload_0
      98: iconst_2
      99: istore_3
     100: dup
     101: ifnonnull     108
     104: pop
     105: goto          117
     108: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
     111: iload_3
     112: if_icmpne     117
     115: iconst_1
     116: ireturn
     117: iconst_1
     118: istore_3
     119: iconst_1
     120: istore        4
     122: iconst_2
     123: istore        5
     125: iload         5
     127: aload_0
     128: dup
     129: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     132: invokevirtual #19                 // Method java/lang/Integer.intValue:()I
     135: if_icmpge     157
     138: iload_3
     139: iload         4
     141: iadd
     142: istore        6
     144: iload         4
     146: istore_3
     147: iload         6
     149: istore        4
     151: iinc          5, 1
     154: goto          125
     157: iload         4
     159: ireturn

  public static int computeFibbonaciNumber$default(java.lang.Integer, boolean, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: aload_0
       9: iload_1
      10: invokestatic  #45                 // Method computeFibbonaciNumber:(Ljava/lang/Integer;Z)I
      13: ireturn

  public static final java.util.List<java.lang.Integer> computeFibbonachiArray(int, int, boolean);
    Code:
       0: iload_2
       1: ifne          117
       4: new           #51                 // class kotlin/ranges/IntRange
       7: dup
       8: iload_0
       9: iload_1
      10: invokespecial #55                 // Method kotlin/ranges/IntRange."<init>":(II)V
      13: checkcast     #57                 // class java/lang/Iterable
      16: astore_3
      17: iconst_0
      18: istore        4
      20: aload_3
      21: astore        5
      23: new           #59                 // class java/util/ArrayList
      26: dup
      27: aload_3
      28: bipush        10
      30: invokestatic  #65                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #68                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #70                 // class java/util/Collection
      39: astore        6
      41: iconst_0
      42: istore        7
      44: aload         5
      46: invokeinterface #74,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        8
      53: aload         8
      55: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          110
      63: aload         8
      65: checkcast     #82                 // class kotlin/collections/IntIterator
      68: invokevirtual #85                 // Method kotlin/collections/IntIterator.nextInt:()I
      71: istore        9
      73: aload         6
      75: iload         9
      77: istore        10
      79: astore        12
      81: iconst_0
      82: istore        11
      84: iload         10
      86: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      89: iconst_0
      90: iconst_2
      91: aconst_null
      92: invokestatic  #87                 // Method computeFibbonaciNumber$default:(Ljava/lang/Integer;ZILjava/lang/Object;)I
      95: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: aload         12
     100: swap
     101: invokeinterface #91,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: goto          53
     110: aload         6
     112: checkcast     #93                 // class java/util/List
     115: nop
     116: areturn
     117: iload_0
     118: iload_1
     119: if_icmple     126
     122: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     125: areturn
     126: iload_0
     127: iload_1
     128: if_icmpne     148
     131: iload_0
     132: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     135: iconst_0
     136: iconst_2
     137: aconst_null
     138: invokestatic  #87                 // Method computeFibbonaciNumber$default:(Ljava/lang/Integer;ZILjava/lang/Object;)I
     141: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     144: invokestatic  #101                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     147: areturn
     148: iconst_2
     149: anewarray     #15                 // class java/lang/Integer
     152: astore        4
     154: aload         4
     156: iconst_0
     157: iload_0
     158: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     161: iconst_0
     162: iconst_2
     163: aconst_null
     164: invokestatic  #87                 // Method computeFibbonaciNumber$default:(Ljava/lang/Integer;ZILjava/lang/Object;)I
     167: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     170: aastore
     171: aload         4
     173: iconst_1
     174: iload_0
     175: iconst_1
     176: iadd
     177: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     180: iconst_0
     181: iconst_2
     182: aconst_null
     183: invokestatic  #87                 // Method computeFibbonaciNumber$default:(Ljava/lang/Integer;ZILjava/lang/Object;)I
     186: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: aastore
     190: aload         4
     192: invokestatic  #105                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     195: astore_3
     196: new           #51                 // class kotlin/ranges/IntRange
     199: dup
     200: iconst_2
     201: iload_1
     202: iload_0
     203: isub
     204: invokespecial #55                 // Method kotlin/ranges/IntRange."<init>":(II)V
     207: checkcast     #57                 // class java/lang/Iterable
     210: astore        4
     212: iconst_0
     213: istore        5
     215: aload         4
     217: invokeinterface #74,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     222: astore        6
     224: aload         6
     226: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          298
     234: aload         6
     236: checkcast     #82                 // class kotlin/collections/IntIterator
     239: invokevirtual #85                 // Method kotlin/collections/IntIterator.nextInt:()I
     242: istore        7
     244: iload         7
     246: istore        8
     248: iconst_0
     249: istore        9
     251: aload_3
     252: aload_3
     253: iload         8
     255: iconst_2
     256: isub
     257: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     262: checkcast     #111                // class java/lang/Number
     265: invokevirtual #112                // Method java/lang/Number.intValue:()I
     268: aload_3
     269: iload         8
     271: iconst_1
     272: isub
     273: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     278: checkcast     #111                // class java/lang/Number
     281: invokevirtual #112                // Method java/lang/Number.intValue:()I
     284: iadd
     285: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     288: invokeinterface #113,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     293: pop
     294: nop
     295: goto          224
     298: nop
     299: aload_3
     300: areturn

  public static java.util.List computeFibbonachiArray$default(int, int, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_4
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_2
       8: iload_0
       9: iload_1
      10: iload_2
      11: invokestatic  #136                // Method computeFibbonachiArray:(IIZ)Ljava/util/List;
      14: areturn

  public static final int recursiveFibbonachi(int, int, int);
    Code:
       0: iload_2
       1: ifge          6
       4: iconst_1
       5: ireturn
       6: iload_2
       7: ifne          14
      10: iload_1
      11: goto          24
      14: iload_1
      15: iload_0
      16: iload_1
      17: iadd
      18: iload_2
      19: iconst_1
      20: isub
      21: invokestatic  #140                // Method recursiveFibbonachi:(III)I
      24: ireturn

  public static final int computeNegativeFibbonachi(int);
    Code:
       0: iload_0
       1: iflt          14
       4: new           #145                // class java/lang/Exception
       7: dup
       8: ldc           #147                // String potition must be smaller than zero!
      10: invokespecial #150                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
      13: athrow
      14: iload_0
      15: iconst_2
      16: irem
      17: ifne          24
      20: iconst_1
      21: goto          25
      24: iconst_0
      25: istore_1
      26: iload_0
      27: ineg
      28: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      31: iconst_0
      32: iconst_2
      33: aconst_null
      34: invokestatic  #87                 // Method computeFibbonaciNumber$default:(Ljava/lang/Integer;ZILjava/lang/Object;)I
      37: istore_2
      38: iload_1
      39: ifeq          48
      42: iload_2
      43: iconst_m1
      44: imul
      45: goto          49
      48: iload_2
      49: ireturn

  public static final int recursiveFibbonachi(int, int, int, int);
    Code:
       0: iload_0
       1: ifne          6
       4: iconst_0
       5: ireturn
       6: iload_3
       7: ifne          12
      10: iload_1
      11: ireturn
      12: iload_0
      13: ifle          28
      16: iload_0
      17: iload_2
      18: iload_1
      19: iload_2
      20: iadd
      21: iload_3
      22: iconst_1
      23: isub
      24: invokestatic  #155                // Method recursiveFibbonachi:(IIII)I
      27: ireturn
      28: iload_0
      29: iload_2
      30: iload_1
      31: isub
      32: iload_1
      33: iload_3
      34: iconst_1
      35: iadd
      36: invokestatic  #155                // Method recursiveFibbonachi:(IIII)I
      39: ireturn

  public static int recursiveFibbonachi$default(int, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_2
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_1
       9: iload         4
      11: iconst_4
      12: iand
      13: ifeq          18
      16: iconst_1
      17: istore_2
      18: iload         4
      20: bipush        8
      22: iand
      23: ifeq          28
      26: iload_0
      27: istore_3
      28: iload_0
      29: iload_1
      30: iload_2
      31: iload_3
      32: invokestatic  #155                // Method recursiveFibbonachi:(IIII)I
      35: ireturn
}


package com.talkspace.exercises

// Write a function that takes as its arguments a sorted array of unique integers, `intArray`, and an integer, `int`, and returns 3 integers from `intArray` that sum up to `int`.
fun main(args: Array<String>) {
    println(threeSum(listOf(-1, 2, 3, 4, 5, 7, 8, 12), 6)) // [4, 3, -1]

    println(twoSum(listOf(-1, 2, 3, 4, 5, 7, 8, 12), 6)) // [4, 2]
    println(twoSum(listOf(-1, 2, 3, 4, 5, 7, 8, 12), 20)) // [12, 8]

}

fun threeSum(ints: List<Int>, total: Int): List<Int> {
    for (integer in ints) {
        val mutableTemp = ints.toMutableList()
        mutableTemp.remove(integer)

        val res = twoSum(mutableTemp, total - integer)

        if (res.isNotEmpty()) {
            val mutableRes = res.toMutableList()
            mutableRes.add(integer)
            return mutableRes
        }
    }

    return listOf()
}

fun twoSum(ints: List<Int>, total: Int): List<Int> {
    val hash = mutableMapOf<Int, Int>()

    for (integer in ints) {
        val matchingSolution = total - integer

        if (hash.containsKey(matchingSolution)) {
            return listOf(integer, matchingSolution)
        } else {
            hash[integer] = matchingSolution
        }
    }

    return listOf()
}

Compiled from "sum3.kt"
public final class com.talkspace.exercises.Sum3Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        8
       8: anewarray     #17                 // class java/lang/Integer
      11: astore_1
      12: aload_1
      13: iconst_0
      14: iconst_m1
      15: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: aastore
      19: aload_1
      20: iconst_1
      21: iconst_2
      22: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: aastore
      26: aload_1
      27: iconst_2
      28: iconst_3
      29: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: aastore
      33: aload_1
      34: iconst_3
      35: iconst_4
      36: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: aastore
      40: aload_1
      41: iconst_4
      42: iconst_5
      43: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: aastore
      47: aload_1
      48: iconst_5
      49: bipush        7
      51: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: aastore
      55: aload_1
      56: bipush        6
      58: bipush        8
      60: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      63: aastore
      64: aload_1
      65: bipush        7
      67: bipush        12
      69: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: aastore
      73: aload_1
      74: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      77: bipush        6
      79: invokestatic  #31                 // Method threeSum:(Ljava/util/List;I)Ljava/util/List;
      82: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
      85: swap
      86: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      89: bipush        8
      91: anewarray     #17                 // class java/lang/Integer
      94: astore_1
      95: aload_1
      96: iconst_0
      97: iconst_m1
      98: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: aastore
     102: aload_1
     103: iconst_1
     104: iconst_2
     105: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aastore
     109: aload_1
     110: iconst_2
     111: iconst_3
     112: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     115: aastore
     116: aload_1
     117: iconst_3
     118: iconst_4
     119: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: aastore
     123: aload_1
     124: iconst_4
     125: iconst_5
     126: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     129: aastore
     130: aload_1
     131: iconst_5
     132: bipush        7
     134: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: aastore
     138: aload_1
     139: bipush        6
     141: bipush        8
     143: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     146: aastore
     147: aload_1
     148: bipush        7
     150: bipush        12
     152: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: aastore
     156: aload_1
     157: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     160: bipush        6
     162: invokestatic  #46                 // Method twoSum:(Ljava/util/List;I)Ljava/util/List;
     165: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
     168: swap
     169: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     172: bipush        8
     174: anewarray     #17                 // class java/lang/Integer
     177: astore_1
     178: aload_1
     179: iconst_0
     180: iconst_m1
     181: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: aastore
     185: aload_1
     186: iconst_1
     187: iconst_2
     188: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     191: aastore
     192: aload_1
     193: iconst_2
     194: iconst_3
     195: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: aastore
     199: aload_1
     200: iconst_3
     201: iconst_4
     202: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     205: aastore
     206: aload_1
     207: iconst_4
     208: iconst_5
     209: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     212: aastore
     213: aload_1
     214: iconst_5
     215: bipush        7
     217: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     220: aastore
     221: aload_1
     222: bipush        6
     224: bipush        8
     226: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     229: aastore
     230: aload_1
     231: bipush        7
     233: bipush        12
     235: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     238: aastore
     239: aload_1
     240: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     243: bipush        20
     245: invokestatic  #46                 // Method twoSum:(Ljava/util/List;I)Ljava/util/List;
     248: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
     251: swap
     252: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     255: return

  public static final java.util.List<java.lang.Integer> threeSum(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #50                 // String ints
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      12: astore_2
      13: aload_2
      14: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      19: ifeq          112
      22: aload_2
      23: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      28: checkcast     #68                 // class java/lang/Number
      31: invokevirtual #72                 // Method java/lang/Number.intValue:()I
      34: istore_3
      35: aload_0
      36: checkcast     #74                 // class java/util/Collection
      39: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      42: astore        4
      44: aload         4
      46: iload_3
      47: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: invokeinterface #82,  2           // InterfaceMethod java/util/List.remove:(Ljava/lang/Object;)Z
      55: pop
      56: aload         4
      58: iload_1
      59: iload_3
      60: isub
      61: invokestatic  #46                 // Method twoSum:(Ljava/util/List;I)Ljava/util/List;
      64: astore        5
      66: aload         5
      68: checkcast     #74                 // class java/util/Collection
      71: invokeinterface #85,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      76: ifne          83
      79: iconst_1
      80: goto          84
      83: iconst_0
      84: ifeq          13
      87: aload         5
      89: checkcast     #74                 // class java/util/Collection
      92: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      95: astore        6
      97: aload         6
      99: iload_3
     100: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     103: invokeinterface #88,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     108: pop
     109: aload         6
     111: areturn
     112: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     115: areturn

  public static final java.util.List<java.lang.Integer> twoSum(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #50                 // String ints
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #101                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #105                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #107                // class java/util/Map
      16: astore_2
      17: aload_0
      18: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      23: astore_3
      24: aload_3
      25: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          125
      33: aload_3
      34: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #68                 // class java/lang/Number
      42: invokevirtual #72                 // Method java/lang/Number.intValue:()I
      45: istore        4
      47: iload_1
      48: iload         4
      50: isub
      51: istore        5
      53: aload_2
      54: iload         5
      56: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: invokeinterface #110,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      64: ifeq          97
      67: iconst_2
      68: anewarray     #17                 // class java/lang/Integer
      71: astore        6
      73: aload         6
      75: iconst_0
      76: iload         4
      78: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: aastore
      82: aload         6
      84: iconst_1
      85: iload         5
      87: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: aastore
      91: aload         6
      93: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      96: areturn
      97: iload         4
      99: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: astore        7
     104: iload         5
     106: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     109: astore        8
     111: aload_2
     112: aload         7
     114: aload         8
     116: invokeinterface #114,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     121: pop
     122: goto          24
     125: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     128: areturn
}