Undiy__hyperskill-kotlin-core__70695fb/Phone Book (Kotlin)/Phone Book (Kotlin)/task/src/phonebook/Main.kt

package phonebook

import java.io.BufferedReader
import java.io.File
import java.io.FileReader
import java.lang.Integer.min
import java.util.*
import kotlin.math.sqrt
import kotlin.streams.asSequence

const val FIND_FILENAME = "find.txt"
const val DIRECTORY_FILENAME = "directory.txt"

fun getRecordName(record: String) = record.substringAfter(" ", record)

fun linearSearchFn(value: String): Boolean {
    BufferedReader(FileReader(DIRECTORY_FILENAME)).use { directoryReader ->
        return directoryReader.lines().anyMatch {
                getRecordName(it) == value
        }
    }
}

fun jumpSearch(data: List<String>, value: String): Boolean {
    val blockSize = sqrt(data.size.toDouble()).toInt()
    for (i in 0..data.size / blockSize) {
        val boundary = min(data.lastIndex, (i + 1) * blockSize - 1)
        if (getRecordName(data[boundary]) >= value) {
            for (j in boundary downTo i * blockSize) {
                if (getRecordName(data[j]) == value) {
                    return true
                }
            }
        }
    }
    return false
}

fun binarySearch(data: List<String>, value: String): Boolean {
    if (data.isEmpty()) {
        return false
    }
    val pivotIndex = data.size / 2
    val pivot = getRecordName(data[pivotIndex])
    return if (pivot == value) {
        true
    } else if (pivot > value) {
        binarySearch(data.subList(0, pivotIndex), value)
    } else {
        binarySearch(data.subList(pivotIndex, data.size), value)
    }
}

fun search(searchFn: (String) -> Boolean) = search(searchFn, System.currentTimeMillis())
fun search(searchFn: (String) -> Boolean, start: Long): Long {
    var count = 0
    var found = 0
    BufferedReader(FileReader(FIND_FILENAME)).use { findReader ->
        findReader.lines().forEach {
            count++
            if (searchFn(it)) {
                found++
            }
        }
    }
    val time = System.currentTimeMillis() - start
    println("Found $found / $count entries. Time taken: ${formatTimeMillis(time)}")
    return time
}

fun bubbleAndJumpSearch(limit: Long): Long {
    val start = System.currentTimeMillis()
    val directory = File(DIRECTORY_FILENAME).readLines()
    val (isSorted, sortTime) = bubbleSort(directory, limit)

    val time = search(if (isSorted) {
         { jumpSearch(directory, it) }
    } else {
        ::linearSearchFn
    }, start)

    if (isSorted) {
        println("Sorting time: ${formatTimeMillis(sortTime)}")
    } else {
        println("Sorting time: ${formatTimeMillis(sortTime)} - STOPPED, moved to linear search")
    }
    println("Searching time: ${formatTimeMillis(time - sortTime)}")
    return time
}

fun formatTimeMillis(millis: Long) = "${millis / 1000_000} min. ${millis % 1000_000 / 1000} sec. ${millis % 1000} ms."

fun bubbleSort(data: List<String>, timeLimit: Long): Pair<Boolean, Long> {
    val start = System.currentTimeMillis()
    var isSorted: Boolean

    do {
        isSorted = true
        for (i in 0 until data.lastIndex) {
            val time = System.currentTimeMillis() - start
            if (time > timeLimit) {
                return Pair(false, time)
            }
            if (getRecordName(data[i]) > getRecordName(data[i + 1])) {
                isSorted = false
                Collections.swap(data, i, i + 1)
            }
        }
    } while (!isSorted)
    return Pair(true, System.currentTimeMillis() - start)
}

fun quickSort(data: List<String>) {
    if (data.size < 2) {
        return
    }
    val pivot = getRecordName(data.random())
    var boundary = 0
    for (i in data.indices) {
        if (getRecordName(data[i]) < pivot) {
            Collections.swap(data, i, boundary)
            boundary++
        }
    }
    quickSort(data.subList(0, boundary))
    quickSort(data.subList(boundary, data.size))
}

fun quickAndBinarySearch(): Long {
    val start = System.currentTimeMillis()
    val directory = File(DIRECTORY_FILENAME).readLines()
    quickSort(directory)

    val sortTime = System.currentTimeMillis() - start

    val time = search({ binarySearch(directory, it) }, start)

    println("Sorting time: ${formatTimeMillis(sortTime)}")
    println("Searching time: ${formatTimeMillis(time - sortTime)}")
    return time
}

fun hashSearch(): Long {
    val start = System.currentTimeMillis()
    val table = BufferedReader(FileReader(DIRECTORY_FILENAME)).use { directoryReader ->
        directoryReader.lines().asSequence().groupBy(
            ::getRecordName
        ) { it.substringBefore(" ", it) }
    }
    val createTime = System.currentTimeMillis() - start

    val time = search({ it in table }, start)

    println("Creating time: ${formatTimeMillis(createTime)}")
    println("Searching time: ${formatTimeMillis(time - createTime)}")
    return time
}

fun main() {
    println("Start searching (linear search)...")
    val linearTime = search(::linearSearchFn)
    println()
    println("Start searching (bubble sort + jump search)...")
    bubbleAndJumpSearch(linearTime * 10)
    println()
    println("Start searching (quick sort + binary search)...")
    quickAndBinarySearch()
    println("Start searching (hash table)...")
    hashSearch()
}

Compiled from "Main.kt"
final class phonebook.MainKt$main$linearTime$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> {
  public static final phonebook.MainKt$main$linearTime$1 INSTANCE;

  phonebook.MainKt$main$linearTime$1();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class phonebook/MainKt
       4: ldc           #13                 // String linearSearchFn
       6: ldc           #15                 // String linearSearchFn(Ljava/lang/String;)Z
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Boolean invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method phonebook/MainKt.linearSearchFn:(Ljava/lang/String;)Z
      10: invokestatic  #39                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class java/lang/String
       5: invokevirtual #45                 // Method invoke:(Ljava/lang/String;)Ljava/lang/Boolean;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class phonebook/MainKt$main$linearTime$1
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lphonebook/MainKt$main$linearTime$1;
      10: return
}

Compiled from "Main.kt"
final class phonebook.MainKt$bubbleAndJumpSearch$time$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> {
  public static final phonebook.MainKt$bubbleAndJumpSearch$time$2 INSTANCE;

  phonebook.MainKt$bubbleAndJumpSearch$time$2();
    Code:
       0: aload_0
       1: iconst_1
       2: ldc           #11                 // class phonebook/MainKt
       4: ldc           #13                 // String linearSearchFn
       6: ldc           #15                 // String linearSearchFn(Ljava/lang/String;)Z
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.Boolean invoke(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokestatic  #33                 // Method phonebook/MainKt.linearSearchFn:(Ljava/lang/String;)Z
      10: invokestatic  #39                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      13: areturn

  public java.lang.Object invoke(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #43                 // class java/lang/String
       5: invokevirtual #45                 // Method invoke:(Ljava/lang/String;)Ljava/lang/Boolean;
       8: areturn

  static {};
    Code:
       0: new           #2                  // class phonebook/MainKt$bubbleAndJumpSearch$time$2
       3: dup
       4: invokespecial #50                 // Method "<init>":()V
       7: putstatic     #53                 // Field INSTANCE:Lphonebook/MainKt$bubbleAndJumpSearch$time$2;
      10: return
}

Compiled from "Main.kt"
public final class phonebook.MainKt {
  public static final java.lang.String FIND_FILENAME;

  public static final java.lang.String DIRECTORY_FILENAME;

  public static final java.lang.String getRecordName(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String record
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #17                 // String
       9: aload_0
      10: invokestatic  #23                 // Method kotlin/text/StringsKt.substringAfter:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      13: areturn

  public static final boolean linearSearchFn(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #30                 // String value
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #32                 // class java/io/BufferedReader
       9: dup
      10: new           #34                 // class java/io/FileReader
      13: dup
      14: ldc           #36                 // String directory.txt
      16: invokespecial #40                 // Method java/io/FileReader."<init>":(Ljava/lang/String;)V
      19: checkcast     #42                 // class java/io/Reader
      22: invokespecial #45                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V
      25: checkcast     #47                 // class java/io/Closeable
      28: astore_1
      29: aconst_null
      30: astore_2
      31: nop
      32: aload_1
      33: checkcast     #32                 // class java/io/BufferedReader
      36: astore_3
      37: iconst_0
      38: istore        4
      40: aload_3
      41: invokevirtual #51                 // Method java/io/BufferedReader.lines:()Ljava/util/stream/Stream;
      44: aload_0
      45: invokedynamic #71,  0             // InvokeDynamic #0:invoke:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
      50: invokedynamic #82,  0             // InvokeDynamic #1:test:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Predicate;
      55: invokeinterface #88,  2           // InterfaceMethod java/util/stream/Stream.anyMatch:(Ljava/util/function/Predicate;)Z
      60: istore        5
      62: aload_1
      63: aload_2
      64: invokestatic  #94                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
      67: iload         5
      69: ireturn
      70: astore        4
      72: aload         4
      74: astore_2
      75: aload         4
      77: athrow
      78: astore        4
      80: aload_1
      81: aload_2
      82: invokestatic  #94                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
      85: aload         4
      87: athrow
    Exception table:
       from    to  target type
          31    62    70   Class java/lang/Throwable
          31    62    78   any
          70    78    78   any
          78    80    78   any

  public static final boolean jumpSearch(java.util.List<java.lang.String>, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #105                // String data
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #30                 // String value
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #111,  1          // InterfaceMethod java/util/List.size:()I
      18: i2d
      19: invokestatic  #117                // Method java/lang/Math.sqrt:(D)D
      22: d2i
      23: istore_2
      24: iconst_0
      25: istore_3
      26: aload_0
      27: invokeinterface #111,  1          // InterfaceMethod java/util/List.size:()I
      32: iload_2
      33: idiv
      34: istore        4
      36: iload_3
      37: iload         4
      39: if_icmpgt     143
      42: aload_0
      43: invokestatic  #123                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      46: iload_3
      47: iconst_1
      48: iadd
      49: iload_2
      50: imul
      51: iconst_1
      52: isub
      53: invokestatic  #129                // Method java/lang/Integer.min:(II)I
      56: istore        5
      58: aload_0
      59: iload         5
      61: invokeinterface #133,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      66: checkcast     #100                // class java/lang/String
      69: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
      72: aload_1
      73: invokevirtual #139                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
      76: iflt          131
      79: iload         5
      81: istore        6
      83: iload_3
      84: iload_2
      85: imul
      86: istore        7
      88: iload         7
      90: iload         6
      92: if_icmpgt     131
      95: aload_0
      96: iload         6
      98: invokeinterface #133,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     103: checkcast     #100                // class java/lang/String
     106: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
     109: aload_1
     110: invokestatic  #143                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     113: ifeq          118
     116: iconst_1
     117: ireturn
     118: iload         6
     120: iload         7
     122: if_icmpeq     131
     125: iinc          6, -1
     128: goto          95
     131: iload_3
     132: iload         4
     134: if_icmpeq     143
     137: iinc          3, 1
     140: goto          42
     143: iconst_0
     144: ireturn

  public static final boolean binarySearch(java.util.List<java.lang.String>, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #105                // String data
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #30                 // String value
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #153,  1          // InterfaceMethod java/util/List.isEmpty:()Z
      18: ifeq          23
      21: iconst_0
      22: ireturn
      23: aload_0
      24: invokeinterface #111,  1          // InterfaceMethod java/util/List.size:()I
      29: iconst_2
      30: idiv
      31: istore_2
      32: aload_0
      33: iload_2
      34: invokeinterface #133,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      39: checkcast     #100                // class java/lang/String
      42: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
      45: astore_3
      46: aload_3
      47: aload_1
      48: invokestatic  #143                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      51: ifeq          58
      54: iconst_1
      55: goto          98
      58: aload_3
      59: aload_1
      60: invokevirtual #139                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
      63: ifle          81
      66: aload_0
      67: iconst_0
      68: iload_2
      69: invokeinterface #157,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      74: aload_1
      75: invokestatic  #159                // Method binarySearch:(Ljava/util/List;Ljava/lang/String;)Z
      78: goto          98
      81: aload_0
      82: iload_2
      83: aload_0
      84: invokeinterface #111,  1          // InterfaceMethod java/util/List.size:()I
      89: invokeinterface #157,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      94: aload_1
      95: invokestatic  #159                // Method binarySearch:(Ljava/util/List;Ljava/lang/String;)Z
      98: ireturn

  public static final long search(kotlin.jvm.functions.Function1<? super java.lang.String, java.lang.Boolean>);
    Code:
       0: aload_0
       1: ldc           #166                // String searchFn
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
      10: invokestatic  #175                // Method search:(Lkotlin/jvm/functions/Function1;J)J
      13: lreturn

  public static final long search(kotlin.jvm.functions.Function1<? super java.lang.String, java.lang.Boolean>, long);
    Code:
       0: aload_0
       1: ldc           #166                // String searchFn
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #179                // class kotlin/jvm/internal/Ref$IntRef
       9: dup
      10: invokespecial #182                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      13: astore_3
      14: new           #179                // class kotlin/jvm/internal/Ref$IntRef
      17: dup
      18: invokespecial #182                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      21: astore        4
      23: new           #32                 // class java/io/BufferedReader
      26: dup
      27: new           #34                 // class java/io/FileReader
      30: dup
      31: ldc           #184                // String find.txt
      33: invokespecial #40                 // Method java/io/FileReader."<init>":(Ljava/lang/String;)V
      36: checkcast     #42                 // class java/io/Reader
      39: invokespecial #45                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V
      42: checkcast     #47                 // class java/io/Closeable
      45: astore        5
      47: aconst_null
      48: astore        6
      50: nop
      51: aload         5
      53: checkcast     #32                 // class java/io/BufferedReader
      56: astore        7
      58: iconst_0
      59: istore        8
      61: aload         7
      63: invokevirtual #51                 // Method java/io/BufferedReader.lines:()Ljava/util/stream/Stream;
      66: aload_3
      67: aload_0
      68: aload         4
      70: invokedynamic #194,  0            // InvokeDynamic #2:invoke:(Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
      75: invokedynamic #205,  0            // InvokeDynamic #3:accept:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Consumer;
      80: invokeinterface #209,  2          // InterfaceMethod java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
      85: nop
      86: getstatic     #215                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      89: astore        7
      91: aload         5
      93: aload         6
      95: invokestatic  #94                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
      98: goto          122
     101: astore        8
     103: aload         8
     105: astore        6
     107: aload         8
     109: athrow
     110: astore        8
     112: aload         5
     114: aload         6
     116: invokestatic  #94                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     119: aload         8
     121: athrow
     122: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
     125: lload_1
     126: lsub
     127: lstore        5
     129: new           #217                // class java/lang/StringBuilder
     132: dup
     133: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
     136: ldc           #220                // String Found
     138: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     141: aload         4
     143: getfield      #227                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     146: invokevirtual #230                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     149: ldc           #232                // String  /
     151: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     154: aload_3
     155: getfield      #227                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     158: invokevirtual #230                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     161: ldc           #234                // String  entries. Time taken:
     163: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     166: lload         5
     168: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
     171: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     174: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     177: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     180: swap
     181: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     184: lload         5
     186: lreturn
    Exception table:
       from    to  target type
          50    91   101   Class java/lang/Throwable
          50    91   110   any
         101   110   110   any
         110   112   110   any

  public static final long bubbleAndJumpSearch(long);
    Code:
       0: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
       3: lstore_2
       4: new           #265                // class java/io/File
       7: dup
       8: ldc           #36                 // String directory.txt
      10: invokespecial #266                // Method java/io/File."<init>":(Ljava/lang/String;)V
      13: aconst_null
      14: iconst_1
      15: aconst_null
      16: invokestatic  #272                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      19: astore        4
      21: aload         4
      23: lload_0
      24: invokestatic  #276                // Method bubbleSort:(Ljava/util/List;J)Lkotlin/Pair;
      27: astore        5
      29: aload         5
      31: invokevirtual #282                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      34: checkcast     #284                // class java/lang/Boolean
      37: invokevirtual #287                // Method java/lang/Boolean.booleanValue:()Z
      40: istore        6
      42: aload         5
      44: invokevirtual #290                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      47: checkcast     #292                // class java/lang/Number
      50: invokevirtual #295                // Method java/lang/Number.longValue:()J
      53: lstore        7
      55: iload         6
      57: ifeq          70
      60: aload         4
      62: invokedynamic #302,  0            // InvokeDynamic #4:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
      67: goto          76
      70: getstatic     #307                // Field phonebook/MainKt$bubbleAndJumpSearch$time$2.INSTANCE:Lphonebook/MainKt$bubbleAndJumpSearch$time$2;
      73: checkcast     #261                // class kotlin/jvm/functions/Function1
      76: lload_2
      77: invokestatic  #175                // Method search:(Lkotlin/jvm/functions/Function1;J)J
      80: lstore        9
      82: iload         6
      84: ifeq          121
      87: new           #217                // class java/lang/StringBuilder
      90: dup
      91: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
      94: ldc_w         #309                // String Sorting time:
      97: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     100: lload         7
     102: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
     105: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     108: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     111: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     114: swap
     115: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     118: goto          158
     121: new           #217                // class java/lang/StringBuilder
     124: dup
     125: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
     128: ldc_w         #309                // String Sorting time:
     131: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     134: lload         7
     136: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
     139: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     142: ldc_w         #311                // String  - STOPPED, moved to linear search
     145: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     148: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     151: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     154: swap
     155: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     158: new           #217                // class java/lang/StringBuilder
     161: dup
     162: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
     165: ldc_w         #313                // String Searching time:
     168: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     171: lload         9
     173: lload         7
     175: lsub
     176: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
     179: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     182: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     185: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     188: swap
     189: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     192: lload         9
     194: lreturn

  public static final java.lang.String formatTimeMillis(long);
    Code:
       0: new           #217                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
       7: lload_0
       8: ldc_w         #319                // int 1000000
      11: i2l
      12: ldiv
      13: invokevirtual #322                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      16: ldc_w         #324                // String  min.
      19: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: lload_0
      23: ldc_w         #319                // int 1000000
      26: i2l
      27: lrem
      28: sipush        1000
      31: i2l
      32: ldiv
      33: invokevirtual #322                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      36: ldc_w         #326                // String  sec.
      39: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: lload_0
      43: sipush        1000
      46: i2l
      47: lrem
      48: invokevirtual #322                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      51: ldc_w         #328                // String  ms.
      54: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      57: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      60: areturn

  public static final kotlin.Pair<java.lang.Boolean, java.lang.Long> bubbleSort(java.util.List<java.lang.String>, long);
    Code:
       0: aload_0
       1: ldc           #105                // String data
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
       9: lstore_3
      10: iconst_0
      11: istore        5
      13: iconst_1
      14: istore        5
      16: iconst_0
      17: istore        6
      19: aload_0
      20: invokestatic  #123                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      23: istore        7
      25: iload         6
      27: iload         7
      29: if_icmpge     118
      32: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
      35: lload_3
      36: lsub
      37: lstore        8
      39: lload         8
      41: lload_1
      42: lcmp
      43: ifle          63
      46: new           #278                // class kotlin/Pair
      49: dup
      50: iconst_0
      51: invokestatic  #334                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      54: lload         8
      56: invokestatic  #339                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      59: invokespecial #342                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      62: areturn
      63: aload_0
      64: iload         6
      66: invokeinterface #133,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      71: checkcast     #100                // class java/lang/String
      74: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
      77: aload_0
      78: iload         6
      80: iconst_1
      81: iadd
      82: invokeinterface #133,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      87: checkcast     #100                // class java/lang/String
      90: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
      93: invokevirtual #139                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
      96: ifle          112
      99: iconst_0
     100: istore        5
     102: aload_0
     103: iload         6
     105: iload         6
     107: iconst_1
     108: iadd
     109: invokestatic  #348                // Method java/util/Collections.swap:(Ljava/util/List;II)V
     112: iinc          6, 1
     115: goto          25
     118: iload         5
     120: ifeq          13
     123: new           #278                // class kotlin/Pair
     126: dup
     127: iconst_1
     128: invokestatic  #334                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     131: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
     134: lload_3
     135: lsub
     136: invokestatic  #339                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     139: invokespecial #342                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     142: areturn

  public static final void quickSort(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #105                // String data
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #111,  1          // InterfaceMethod java/util/List.size:()I
      12: iconst_2
      13: if_icmpge     17
      16: return
      17: aload_0
      18: checkcast     #354                // class java/util/Collection
      21: getstatic     #360                // Field kotlin/random/Random.Default:Lkotlin/random/Random$Default;
      24: checkcast     #356                // class kotlin/random/Random
      27: invokestatic  #364                // Method kotlin/collections/CollectionsKt.random:(Ljava/util/Collection;Lkotlin/random/Random;)Ljava/lang/Object;
      30: checkcast     #100                // class java/lang/String
      33: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
      36: astore_1
      37: iconst_0
      38: istore_2
      39: iconst_0
      40: istore_3
      41: aload_0
      42: checkcast     #354                // class java/util/Collection
      45: invokeinterface #365,  1          // InterfaceMethod java/util/Collection.size:()I
      50: istore        4
      52: iload_3
      53: iload         4
      55: if_icmpge     93
      58: aload_0
      59: iload_3
      60: invokeinterface #133,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      65: checkcast     #100                // class java/lang/String
      68: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
      71: aload_1
      72: invokevirtual #139                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
      75: ifge          87
      78: aload_0
      79: iload_3
      80: iload_2
      81: invokestatic  #348                // Method java/util/Collections.swap:(Ljava/util/List;II)V
      84: iinc          2, 1
      87: iinc          3, 1
      90: goto          52
      93: aload_0
      94: iconst_0
      95: iload_2
      96: invokeinterface #157,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     101: invokestatic  #367                // Method quickSort:(Ljava/util/List;)V
     104: aload_0
     105: iload_2
     106: aload_0
     107: invokeinterface #111,  1          // InterfaceMethod java/util/List.size:()I
     112: invokeinterface #157,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     117: invokestatic  #367                // Method quickSort:(Ljava/util/List;)V
     120: return

  public static final long quickAndBinarySearch();
    Code:
       0: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
       3: lstore_0
       4: new           #265                // class java/io/File
       7: dup
       8: ldc           #36                 // String directory.txt
      10: invokespecial #266                // Method java/io/File."<init>":(Ljava/lang/String;)V
      13: aconst_null
      14: iconst_1
      15: aconst_null
      16: invokestatic  #272                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      19: astore_2
      20: aload_2
      21: invokestatic  #367                // Method quickSort:(Ljava/util/List;)V
      24: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
      27: lload_0
      28: lsub
      29: lstore_3
      30: aload_2
      31: invokedynamic #373,  0            // InvokeDynamic #5:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
      36: lload_0
      37: invokestatic  #175                // Method search:(Lkotlin/jvm/functions/Function1;J)J
      40: lstore        5
      42: new           #217                // class java/lang/StringBuilder
      45: dup
      46: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
      49: ldc_w         #309                // String Sorting time:
      52: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      55: lload_3
      56: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
      59: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      62: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      65: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      68: swap
      69: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      72: new           #217                // class java/lang/StringBuilder
      75: dup
      76: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
      79: ldc_w         #313                // String Searching time:
      82: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      85: lload         5
      87: lload_3
      88: lsub
      89: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
      92: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      95: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      98: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     101: swap
     102: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     105: lload         5
     107: lreturn

  public static final long hashSearch();
    Code:
       0: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
       3: lstore_0
       4: new           #32                 // class java/io/BufferedReader
       7: dup
       8: new           #34                 // class java/io/FileReader
      11: dup
      12: ldc           #36                 // String directory.txt
      14: invokespecial #40                 // Method java/io/FileReader."<init>":(Ljava/lang/String;)V
      17: checkcast     #42                 // class java/io/Reader
      20: invokespecial #45                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V
      23: checkcast     #47                 // class java/io/Closeable
      26: astore_3
      27: aconst_null
      28: astore        4
      30: nop
      31: aload_3
      32: checkcast     #32                 // class java/io/BufferedReader
      35: astore        5
      37: iconst_0
      38: istore        6
      40: aload         5
      42: invokevirtual #51                 // Method java/io/BufferedReader.lines:()Ljava/util/stream/Stream;
      45: dup
      46: ldc_w         #376                // String lines(...)
      49: invokestatic  #379                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      52: invokestatic  #385                // Method kotlin/streams/jdk8/StreamsKt.asSequence:(Ljava/util/stream/Stream;)Lkotlin/sequences/Sequence;
      55: astore        7
      57: iconst_0
      58: istore        8
      60: aload         7
      62: astore        9
      64: new           #387                // class java/util/LinkedHashMap
      67: dup
      68: invokespecial #388                // Method java/util/LinkedHashMap."<init>":()V
      71: checkcast     #390                // class java/util/Map
      74: astore        10
      76: iconst_0
      77: istore        11
      79: aload         9
      81: invokeinterface #396,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      86: astore        12
      88: aload         12
      90: invokeinterface #401,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      95: ifeq          227
      98: aload         12
     100: invokeinterface #404,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     105: astore        13
     107: aload         13
     109: checkcast     #100                // class java/lang/String
     112: astore        14
     114: iconst_0
     115: istore        15
     117: aload         14
     119: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
     122: astore        16
     124: aload         10
     126: astore        17
     128: iconst_0
     129: istore        18
     131: aload         17
     133: aload         16
     135: invokeinterface #406,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     140: astore        19
     142: aload         19
     144: ifnonnull     179
     147: iconst_0
     148: istore        20
     150: new           #408                // class java/util/ArrayList
     153: dup
     154: invokespecial #409                // Method java/util/ArrayList."<init>":()V
     157: checkcast     #107                // class java/util/List
     160: astore        20
     162: aload         17
     164: aload         16
     166: aload         20
     168: invokeinterface #413,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     173: pop
     174: aload         20
     176: goto          181
     179: aload         19
     181: nop
     182: checkcast     #107                // class java/util/List
     185: astore        14
     187: aload         14
     189: aload         13
     191: checkcast     #100                // class java/lang/String
     194: astore        15
     196: astore        21
     198: iconst_0
     199: istore        22
     201: aload         15
     203: invokestatic  #416                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     206: aload         15
     208: ldc           #17                 // String
     210: aload         15
     212: invokestatic  #419                // Method kotlin/text/StringsKt.substringBefore:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
     215: aload         21
     217: swap
     218: invokeinterface #422,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     223: pop
     224: goto          88
     227: aload         10
     229: nop
     230: nop
     231: astore        5
     233: aload_3
     234: aload         4
     236: invokestatic  #94                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     239: aload         5
     241: goto          264
     244: astore        6
     246: aload         6
     248: astore        4
     250: aload         6
     252: athrow
     253: astore        6
     255: aload_3
     256: aload         4
     258: invokestatic  #94                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     261: aload         6
     263: athrow
     264: astore_2
     265: invokestatic  #172                // Method java/lang/System.currentTimeMillis:()J
     268: lload_0
     269: lsub
     270: lstore_3
     271: aload_2
     272: invokedynamic #430,  0            // InvokeDynamic #6:invoke:(Ljava/util/Map;)Lkotlin/jvm/functions/Function1;
     277: lload_0
     278: invokestatic  #175                // Method search:(Lkotlin/jvm/functions/Function1;J)J
     281: lstore        5
     283: new           #217                // class java/lang/StringBuilder
     286: dup
     287: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
     290: ldc_w         #432                // String Creating time:
     293: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     296: lload_3
     297: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
     300: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     303: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     306: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     309: swap
     310: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     313: new           #217                // class java/lang/StringBuilder
     316: dup
     317: invokespecial #218                // Method java/lang/StringBuilder."<init>":()V
     320: ldc_w         #313                // String Searching time:
     323: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     326: lload         5
     328: lload_3
     329: lsub
     330: invokestatic  #238                // Method formatTimeMillis:(J)Ljava/lang/String;
     333: invokevirtual #224                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     336: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     339: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
     342: swap
     343: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     346: lload         5
     348: lreturn
    Exception table:
       from    to  target type
          30   233   244   Class java/lang/Throwable
          30   233   253   any
         244   253   253   any
         253   255   253   any

  public static final void main();
    Code:
       0: ldc_w         #458                // String Start searching (linear search)...
       3: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
       6: swap
       7: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      10: getstatic     #463                // Field phonebook/MainKt$main$linearTime$1.INSTANCE:Lphonebook/MainKt$main$linearTime$1;
      13: checkcast     #261                // class kotlin/jvm/functions/Function1
      16: invokestatic  #465                // Method search:(Lkotlin/jvm/functions/Function1;)J
      19: lstore_0
      20: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      23: invokevirtual #467                // Method java/io/PrintStream.println:()V
      26: ldc_w         #469                // String Start searching (bubble sort + jump search)...
      29: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      32: swap
      33: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      36: lload_0
      37: bipush        10
      39: i2l
      40: lmul
      41: invokestatic  #471                // Method bubbleAndJumpSearch:(J)J
      44: pop2
      45: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      48: invokevirtual #467                // Method java/io/PrintStream.println:()V
      51: ldc_w         #473                // String Start searching (quick sort + binary search)...
      54: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      57: swap
      58: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      61: invokestatic  #475                // Method quickAndBinarySearch:()J
      64: pop2
      65: ldc_w         #477                // String Start searching (hash table)...
      68: getstatic     #246                // Field java/lang/System.out:Ljava/io/PrintStream;
      71: swap
      72: invokevirtual #251                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      75: invokestatic  #479                // Method hashSearch:()J
      78: pop2
      79: return

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

  private static final boolean linearSearchFn$lambda$2$lambda$0(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: invokestatic  #416                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       4: aload_1
       5: invokestatic  #135                // Method getRecordName:(Ljava/lang/String;)Ljava/lang/String;
       8: aload_0
       9: invokestatic  #143                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      12: ireturn

  private static final boolean linearSearchFn$lambda$2$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #488,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #284                // class java/lang/Boolean
      10: invokevirtual #287                // Method java/lang/Boolean.booleanValue:()Z
      13: ireturn

  private static final kotlin.Unit search$lambda$5$lambda$3(kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.functions.Function1, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload_0
       1: getfield      #227                // Field kotlin/jvm/internal/Ref$IntRef.element:I
       4: istore        4
       6: aload_0
       7: iload         4
       9: iconst_1
      10: iadd
      11: putfield      #227                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      14: aload_1
      15: aload_3
      16: invokestatic  #416                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      19: aload_3
      20: invokeinterface #488,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      25: checkcast     #284                // class java/lang/Boolean
      28: invokevirtual #287                // Method java/lang/Boolean.booleanValue:()Z
      31: ifeq          48
      34: aload_2
      35: getfield      #227                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      38: istore        4
      40: aload_2
      41: iload         4
      43: iconst_1
      44: iadd
      45: putfield      #227                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      48: getstatic     #215                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      51: areturn

  private static final void search$lambda$5$lambda$4(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #488,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: pop
       8: return

  private static final boolean bubbleAndJumpSearch$lambda$6(java.util.List, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #493                // String it
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokestatic  #495                // Method jumpSearch:(Ljava/util/List;Ljava/lang/String;)Z
      12: ireturn

  private static final boolean quickAndBinarySearch$lambda$7(java.util.List, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #493                // String it
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokestatic  #159                // Method binarySearch:(Ljava/util/List;Ljava/lang/String;)Z
      12: ireturn

  private static final boolean hashSearch$lambda$10(java.util.Map, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #493                // String it
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokeinterface #499,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      14: ireturn
}


package com.example.rain_demo.algorithm

/**
 *@author: Rain
 *@time: 2022/7/14 9:40
 *@version: 1.0
 *@description: 给定一个整数数组 nums 和一个整数目标值 target，请你在该数组中找出 和为目标值 target  的那 两个 整数，并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是，数组中同一个元素在答案里不能重复出现。
 */

/**
 * 输入：nums = [2,7,11,15], target = 9
 * 输出：[0,1]
 * 解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1] 。
 *
 * 输入：nums = [3,2,4], target = 6
 * 输出：[1,2]
 *
 * 输入：nums = [3,3], target = 6
 * 输出：[0,1]
 *
 */
fun main() {
//    val time1 = System.currentTimeMillis()
    val newInt = IntArray(2)
//    sum(newInt, intArrayOf(3, 2, 3), 0, 6)
//    println(System.currentTimeMillis() - time1)
//    println(newInt.toString())
    val nums = intArrayOf(3, 2, 3)
    val target = 6
//    val size = nums.size
//    repeat(size) { index0 ->
//        var index = index0 + 1
//        while (index < size) {
//            if (nums[index0] + nums[index] == target) {
//                newInt[0] = index0
//                newInt[1] = index
//                return
//            }
//            index++
//        }
//    }

    val map = mutableMapOf<Int, Int>()
    var index = 0
    while (index < nums.size) {
        if (map.containsKey(target - nums[index])) {
            val intArrayOf = intArrayOf(map[target - nums[index]]!!, index)
            println(intArrayOf[0])
            println(intArrayOf[1])
        }
        map[nums[index]] = index
        index++
    }
//    nums.forEachIndexed { index, i ->
//        if (map.containsKey(target - i)) {
//            val intArrayOf = intArrayOf(map[target - i]!!, index)
//        }
//        map[i] = index
//    }
}

fun sum(newInt: IntArray, nums: IntArray, index: Int, target: Int) {

    val size = nums.size
    if (index == size - 1) {
        return
    }
    var newIndex = index + 1
//    floor(newInt, nums, index, target, size, newIndex)
    while (newIndex < size) {
        val i = nums[index] + nums[newIndex]
        if (i == target) {
            newInt[0] = index
            newInt[1] = newIndex
            return
        }
        newIndex++
    }
    if (newInt[1] == 0) {
        sum(newInt, nums, index + 1, target)
    }

}

/**
 * 二层递归
 * @param newIndex 后一个index
 */
fun floor(newInt: IntArray, nums: IntArray, index: Int, target: Int, size: Int, newIndex: Int) {
    if (newIndex == size) {
        return
    }
    val i = nums[index] + nums[newIndex]
    if (i == target) {
        newInt[0] = index
        newInt[1] = newIndex
        return
    } else {
        floor(newInt, nums, index, target, size, newIndex + 1)
    }
}

Compiled from "两数之和1.kt"
public final class com.example.rain_demo.algorithm.两数之和1Kt {
  public static final void main();
    Code:
       0: iconst_2
       1: newarray       int
       3: astore_0
       4: iconst_3
       5: newarray       int
       7: astore_2
       8: aload_2
       9: iconst_0
      10: iconst_3
      11: iastore
      12: aload_2
      13: iconst_1
      14: iconst_2
      15: iastore
      16: aload_2
      17: iconst_2
      18: iconst_3
      19: iastore
      20: aload_2
      21: astore_1
      22: bipush        6
      24: istore_2
      25: new           #8                  // class java/util/LinkedHashMap
      28: dup
      29: invokespecial #11                 // Method java/util/LinkedHashMap."<init>":()V
      32: checkcast     #13                 // class java/util/Map
      35: astore_3
      36: iconst_0
      37: istore        4
      39: iload         4
      41: aload_1
      42: arraylength
      43: if_icmpge     165
      46: aload_3
      47: iload_2
      48: aload_1
      49: iload         4
      51: iaload
      52: isub
      53: invokestatic  #19                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: invokeinterface #23,  2           // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      61: ifeq          136
      64: iconst_2
      65: newarray       int
      67: astore        6
      69: aload         6
      71: iconst_0
      72: aload_3
      73: iload_2
      74: aload_1
      75: iload         4
      77: iaload
      78: isub
      79: invokestatic  #19                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      82: invokeinterface #27,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      87: dup
      88: invokestatic  #33                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      91: checkcast     #35                 // class java/lang/Number
      94: invokevirtual #39                 // Method java/lang/Number.intValue:()I
      97: iastore
      98: aload         6
     100: iconst_1
     101: iload         4
     103: iastore
     104: aload         6
     106: astore        5
     108: aload         5
     110: iconst_0
     111: iaload
     112: istore        6
     114: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
     117: iload         6
     119: invokevirtual #51                 // Method java/io/PrintStream.println:(I)V
     122: aload         5
     124: iconst_1
     125: iaload
     126: istore        6
     128: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
     131: iload         6
     133: invokevirtual #51                 // Method java/io/PrintStream.println:(I)V
     136: iload         4
     138: invokestatic  #19                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     141: astore        7
     143: aload_3
     144: aload_1
     145: iload         4
     147: iaload
     148: invokestatic  #19                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     151: aload         7
     153: invokeinterface #55,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     158: pop
     159: iinc          4, 1
     162: goto          39
     165: return

  public static final void sum(int[], int[], int, int);
    Code:
       0: aload_0
       1: ldc           #69                 // String newInt
       3: invokestatic  #73                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #74                 // String nums
       9: invokestatic  #73                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: arraylength
      14: istore        4
      16: iload_2
      17: iload         4
      19: iconst_1
      20: isub
      21: if_icmpne     25
      24: return
      25: iload_2
      26: iconst_1
      27: iadd
      28: istore        5
      30: iload         5
      32: iload         4
      34: if_icmpge     69
      37: aload_1
      38: iload_2
      39: iaload
      40: aload_1
      41: iload         5
      43: iaload
      44: iadd
      45: istore        6
      47: iload         6
      49: iload_3
      50: if_icmpne     63
      53: aload_0
      54: iconst_0
      55: iload_2
      56: iastore
      57: aload_0
      58: iconst_1
      59: iload         5
      61: iastore
      62: return
      63: iinc          5, 1
      66: goto          30
      69: aload_0
      70: iconst_1
      71: iaload
      72: ifne          84
      75: aload_0
      76: aload_1
      77: iload_2
      78: iconst_1
      79: iadd
      80: iload_3
      81: invokestatic  #76                 // Method sum:([I[III)V
      84: return

  public static final void floor(int[], int[], int, int, int, int);
    Code:
       0: aload_0
       1: ldc           #69                 // String newInt
       3: invokestatic  #73                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #74                 // String nums
       9: invokestatic  #73                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload         5
      14: iload         4
      16: if_icmpne     20
      19: return
      20: aload_1
      21: iload_2
      22: iaload
      23: aload_1
      24: iload         5
      26: iaload
      27: iadd
      28: istore        6
      30: iload         6
      32: iload_3
      33: if_icmpne     46
      36: aload_0
      37: iconst_0
      38: iload_2
      39: iastore
      40: aload_0
      41: iconst_1
      42: iload         5
      44: iastore
      45: return
      46: aload_0
      47: aload_1
      48: iload_2
      49: iload_3
      50: iload         4
      52: iload         5
      54: iconst_1
      55: iadd
      56: invokestatic  #83                 // Method floor:([I[IIIII)V
      59: return

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


package com.example.rain_demo.algorithm

/**
 *@author: Rain
 *@time: 2022/7/20 14:34
 *@version: 1.0
 *@description: 寻找两个正序数组的中位数
 */

fun main() {
    val nums1 = intArrayOf(1, 3)
    val nums2 = intArrayOf(2)

    val size1 = nums1.size
    val size2 = nums2.size
    val size = size1 + size2
    if (size % 2 == 0) {
        val midIndex1 = size / 2 - 1
        val midIndex2 = size / 2
        val d = (getKthElement(nums1, nums2, midIndex1 + 1) + getKthElement(nums1,
            nums2,
            midIndex2 + 1)) / 2.0
        println(d)
    } else {
        val midIndex = size / 2
        val kthElement = getKthElement(nums1, nums2, midIndex + 1).toDouble()
        println(kthElement)
    }

}

fun getKthElement(nums1: IntArray, nums2: IntArray, k: Int): Int {
    val size1 = nums1.size
    val size2 = nums2.size
    var index1 = 0
    var index2 = 0
    var ele = k

    while (true) {
        if (index1 == size1) {
            return nums2[index2 + ele - 1]
        }
        if (index2 == size2) {
            return nums1[index1 + ele - 1]
        }
        if (ele == 1) {
            return Math.min(nums1[index1], nums2[index2])
        }
        val h = ele / 2
        val newIndex1 = Math.min(index1 + h, size1) - 1
        val newIndex2 = Math.min(index2 + h, size2) - 1
        val p1 = nums1[newIndex1]
        val p2 = nums2[newIndex2]
        if (p1 <= p2) {
            ele -= (newIndex1 - index1 + 1)
            index1 = newIndex1 + 1
        } else {
            ele -= (newIndex2 - index2 + 1)
            index2 = newIndex2 + 1
        }
    }
}

//region 调用 list api
fun findMedianSortedArrays() {
    val nums1 = intArrayOf(1, 2)
    val nums2 = intArrayOf(3, 4)

    val newNum = DoubleArray(nums1.size + nums2.size)
    val index = add(newNum, nums1, 0)
    val size = second(newNum, nums2, 0, index)
    newNum.sort()
    if (size % 2 == 0) {
        val i = size / 2
        val i1 = i - 1
        val i2: Double = ((newNum[i] + newNum[i1]) / 2)
        println(i2)
    } else {
        val i = (size - 1) / 2
        val i1 = newNum[i]
        println(i1)
    }
}

fun add(newNum: DoubleArray, l: IntArray, index: Int): Int {
    return if (index < l.size) {
        newNum[index] = l[index].toDouble()
        add(newNum, l, index + 1)
    } else {
        index
    }
}

fun second(newNum: DoubleArray, l: IntArray, index: Int, newIndex: Int): Int {
    return if (index < l.size) {
        newNum[newIndex] = l[index].toDouble()
        second(newNum, l, index + 1, newIndex + 1)
    } else {
        newIndex
    }
}
//endregion

Compiled from "寻找两个正序数组的中位数4.kt"
public final class com.example.rain_demo.algorithm.寻找两个正序数组的中位数4Kt {
  public static final void main();
    Code:
       0: iconst_2
       1: newarray       int
       3: astore_1
       4: aload_1
       5: iconst_0
       6: iconst_1
       7: iastore
       8: aload_1
       9: iconst_1
      10: iconst_3
      11: iastore
      12: aload_1
      13: astore_0
      14: iconst_1
      15: newarray       int
      17: astore_2
      18: aload_2
      19: iconst_0
      20: iconst_2
      21: iastore
      22: aload_2
      23: astore_1
      24: aload_0
      25: arraylength
      26: istore_2
      27: aload_1
      28: arraylength
      29: istore_3
      30: iload_2
      31: iload_3
      32: iadd
      33: istore        4
      35: iload         4
      37: iconst_2
      38: irem
      39: ifne          93
      42: iload         4
      44: iconst_2
      45: idiv
      46: iconst_1
      47: isub
      48: istore        5
      50: iload         4
      52: iconst_2
      53: idiv
      54: istore        6
      56: aload_0
      57: aload_1
      58: iload         5
      60: iconst_1
      61: iadd
      62: invokestatic  #10                 // Method getKthElement:([I[II)I
      65: aload_0
      66: aload_1
      67: iload         6
      69: iconst_1
      70: iadd
      71: invokestatic  #10                 // Method getKthElement:([I[II)I
      74: iadd
      75: i2d
      76: ldc2_w        #11                 // double 2.0d
      79: ddiv
      80: dstore        7
      82: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      85: dload         7
      87: invokevirtual #24                 // Method java/io/PrintStream.println:(D)V
      90: goto          119
      93: iload         4
      95: iconst_2
      96: idiv
      97: istore        5
      99: aload_0
     100: aload_1
     101: iload         5
     103: iconst_1
     104: iadd
     105: invokestatic  #10                 // Method getKthElement:([I[II)I
     108: i2d
     109: dstore        6
     111: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
     114: dload         6
     116: invokevirtual #24                 // Method java/io/PrintStream.println:(D)V
     119: return

  public static final int getKthElement(int[], int[], int);
    Code:
       0: aload_0
       1: ldc           #40                 // String nums1
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #47                 // String nums2
       9: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: arraylength
      14: istore_3
      15: aload_1
      16: arraylength
      17: istore        4
      19: iconst_0
      20: istore        5
      22: iconst_0
      23: istore        6
      25: iload_2
      26: istore        7
      28: nop
      29: iload         5
      31: iload_3
      32: if_icmpne     45
      35: aload_1
      36: iload         6
      38: iload         7
      40: iadd
      41: iconst_1
      42: isub
      43: iaload
      44: ireturn
      45: iload         6
      47: iload         4
      49: if_icmpne     62
      52: aload_0
      53: iload         5
      55: iload         7
      57: iadd
      58: iconst_1
      59: isub
      60: iaload
      61: ireturn
      62: iload         7
      64: iconst_1
      65: if_icmpne     80
      68: aload_0
      69: iload         5
      71: iaload
      72: aload_1
      73: iload         6
      75: iaload
      76: invokestatic  #53                 // Method java/lang/Math.min:(II)I
      79: ireturn
      80: iload         7
      82: iconst_2
      83: idiv
      84: istore        8
      86: iload         5
      88: iload         8
      90: iadd
      91: iload_3
      92: invokestatic  #53                 // Method java/lang/Math.min:(II)I
      95: iconst_1
      96: isub
      97: istore        9
      99: iload         6
     101: iload         8
     103: iadd
     104: iload         4
     106: invokestatic  #53                 // Method java/lang/Math.min:(II)I
     109: iconst_1
     110: isub
     111: istore        10
     113: aload_0
     114: iload         9
     116: iaload
     117: istore        11
     119: aload_1
     120: iload         10
     122: iaload
     123: istore        12
     125: iload         11
     127: iload         12
     129: if_icmpgt     153
     132: iload         7
     134: iload         9
     136: iload         5
     138: isub
     139: iconst_1
     140: iadd
     141: isub
     142: istore        7
     144: iload         9
     146: iconst_1
     147: iadd
     148: istore        5
     150: goto          28
     153: iload         7
     155: iload         10
     157: iload         6
     159: isub
     160: iconst_1
     161: iadd
     162: isub
     163: istore        7
     165: iload         10
     167: iconst_1
     168: iadd
     169: istore        6
     171: goto          28

  public static final void findMedianSortedArrays();
    Code:
       0: iconst_2
       1: newarray       int
       3: astore_1
       4: aload_1
       5: iconst_0
       6: iconst_1
       7: iastore
       8: aload_1
       9: iconst_1
      10: iconst_2
      11: iastore
      12: aload_1
      13: astore_0
      14: iconst_2
      15: newarray       int
      17: astore_2
      18: aload_2
      19: iconst_0
      20: iconst_3
      21: iastore
      22: aload_2
      23: iconst_1
      24: iconst_4
      25: iastore
      26: aload_2
      27: astore_1
      28: aload_0
      29: arraylength
      30: aload_1
      31: arraylength
      32: iadd
      33: newarray       double
      35: astore_2
      36: aload_2
      37: aload_0
      38: iconst_0
      39: invokestatic  #67                 // Method add:([D[II)I
      42: istore_3
      43: aload_2
      44: aload_1
      45: iconst_0
      46: iload_3
      47: invokestatic  #71                 // Method second:([D[III)I
      50: istore        4
      52: aload_2
      53: invokestatic  #77                 // Method kotlin/collections/ArraysKt.sort:([D)V
      56: iload         4
      58: iconst_2
      59: irem
      60: ifne          100
      63: iload         4
      65: iconst_2
      66: idiv
      67: istore        5
      69: iload         5
      71: iconst_1
      72: isub
      73: istore        6
      75: aload_2
      76: iload         5
      78: daload
      79: aload_2
      80: iload         6
      82: daload
      83: dadd
      84: iconst_2
      85: i2d
      86: ddiv
      87: dstore        7
      89: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: dload         7
      94: invokevirtual #24                 // Method java/io/PrintStream.println:(D)V
      97: goto          122
     100: iload         4
     102: iconst_1
     103: isub
     104: iconst_2
     105: idiv
     106: istore        5
     108: aload_2
     109: iload         5
     111: daload
     112: dstore        6
     114: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
     117: dload         6
     119: invokevirtual #24                 // Method java/io/PrintStream.println:(D)V
     122: return

  public static final int add(double[], int[], int);
    Code:
       0: aload_0
       1: ldc           #85                 // String newNum
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #87                 // String l
       9: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: aload_1
      14: arraylength
      15: if_icmpge     36
      18: aload_0
      19: iload_2
      20: aload_1
      21: iload_2
      22: iaload
      23: i2d
      24: dastore
      25: aload_0
      26: aload_1
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokestatic  #67                 // Method add:([D[II)I
      33: goto          37
      36: iload_2
      37: ireturn

  public static final int second(double[], int[], int, int);
    Code:
       0: aload_0
       1: ldc           #85                 // String newNum
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #87                 // String l
       9: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: aload_1
      14: arraylength
      15: if_icmpge     39
      18: aload_0
      19: iload_3
      20: aload_1
      21: iload_2
      22: iaload
      23: i2d
      24: dastore
      25: aload_0
      26: aload_1
      27: iload_2
      28: iconst_1
      29: iadd
      30: iload_3
      31: iconst_1
      32: iadd
      33: invokestatic  #71                 // Method second:([D[III)I
      36: goto          40
      39: iload_3
      40: ireturn

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


package com.example.rain_demo.algorithm

/**
 *@author: Rain
 *@time: 2022/7/14 9:33
 *@version: 1.0
 *@description: 一维数组的动态和
 * 给你一个数组 nums 。数组「动态和」的计算公式为：runningSum[i] = sum(nums[0]…nums[i])。请返回 nums 的动态和。
 * val nums = intArrayOf(3, 1, 2, 10, 1)
 * val nums = intArrayOf(1,2,3,4)
 */
fun main() {

    val nums = intArrayOf(1, 1, 1, 1, 1)
    var index = 1
    while (index < nums.size) {
        nums[index] += nums[index - 1]
        index++
    }

//    val mapIndexed = nums.mapIndexed { index, i ->
//        i.plus(nums.take(index).sum())
//    }
//    val size = nums.size
//    val newNum = IntArray(size)
//    nums.forEachIndexed { index, i ->
//        newNum[index] = i.plus(nums.take(index).sum())
//    }
//    mapIndexed.toIntArray()
//    sumArr(newNum, nums, size - 1)
    println(nums.toString())

}

/**
 * 递归方案
 */
fun sumArr(newNum: IntArray, nums: IntArray, index: Int): Int {
    if (index == 0) {
        newNum[0] = nums[0]
        return nums[0]
    }
    newNum[index] = nums[index] + sumArr(newNum, nums, index - 1)

    return newNum[index]
}

Compiled from "一维数组的动态和1480.kt"
public final class com.example.rain_demo.algorithm.一维数组的动态和1480Kt {
  public static final void main();
    Code:
       0: iconst_5
       1: newarray       int
       3: astore_1
       4: aload_1
       5: iconst_0
       6: iconst_1
       7: iastore
       8: aload_1
       9: iconst_1
      10: iconst_1
      11: iastore
      12: aload_1
      13: iconst_2
      14: iconst_1
      15: iastore
      16: aload_1
      17: iconst_3
      18: iconst_1
      19: iastore
      20: aload_1
      21: iconst_4
      22: iconst_1
      23: iastore
      24: aload_1
      25: astore_0
      26: iconst_1
      27: istore_1
      28: iload_1
      29: aload_0
      30: arraylength
      31: if_icmpge     54
      34: iload_1
      35: istore_2
      36: aload_0
      37: iload_2
      38: aload_0
      39: iload_2
      40: iaload
      41: aload_0
      42: iload_1
      43: iconst_1
      44: isub
      45: iaload
      46: iadd
      47: iastore
      48: iinc          1, 1
      51: goto          28
      54: aload_0
      55: invokevirtual #12                 // Method "[I".toString:()Ljava/lang/String;
      58: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: swap
      62: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: return

  public static final int sumArr(int[], int[], int);
    Code:
       0: aload_0
       1: ldc           #32                 // String newNum
       3: invokestatic  #38                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #39                 // String nums
       9: invokestatic  #38                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: ifne          26
      16: aload_0
      17: iconst_0
      18: aload_1
      19: iconst_0
      20: iaload
      21: iastore
      22: aload_1
      23: iconst_0
      24: iaload
      25: ireturn
      26: aload_0
      27: iload_2
      28: aload_1
      29: iload_2
      30: iaload
      31: aload_0
      32: aload_1
      33: iload_2
      34: iconst_1
      35: isub
      36: invokestatic  #41                 // Method sumArr:([I[II)I
      39: iadd
      40: iastore
      41: aload_0
      42: iload_2
      43: iaload
      44: ireturn

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