package com.kotlinspirit.ext

import java.util.StringJoiner

internal operator fun CharRange.minus(range: CharRange): List<CharRange> {
    if (range.first <= this.first && range.last >= this.last) {
        return emptyList()
    }

    return if (range.first > this.first && range.last < this.last) {
        listOf(
            first until range.first, (range.last + 1)..last
        )
    } else if (range.first <= this.first && range.last >= this.first) {
        listOf(
            (range.last + 1)..this.last
        )
    } else if (range.first > this.first && range.last >= this.last && range.first <= this.last) {
        listOf(
            this.first until range.first
        )
    } else {
        listOf(this)
    }
}

internal operator fun CharRange.plus(range: CharRange): List<CharRange> {
    return when {
        range.first <= this.first && range.last >= this.last -> {
            listOf(range)
        }
        this.first <= range.first && this.last >= range.last -> {
            listOf(this)
        }
        range.first <= this.first && range.last <= this.last && range.last >= this.first - 1 -> {
            listOf(range.first..this.last)
        }
        range.first > this.first && range.last >= this.last && range.first <= this.last + 1 -> {
            listOf(this.first..range.last)
        }
        else -> {
            return listOf(this, range)
        }
    }
}

// List should be sorted by first
private fun List<CharRange>.optimizeRanges(): List<CharRange> {
    if (size <= 1) {
        return this
    }

    val result = arrayListOf(this[0])
    var i = 1
    val size = this.size
    while (i < size) {
        result.addAll(result.removeLast() + this[i])
        i++
    }

    return result
}

internal fun List<CharRange>.includeRanges(ranges: List<CharRange>): List<CharRange> {
    return (this + ranges).sortedBy {
        it.first
    }.optimizeRanges()
}

internal fun List<CharRange>.excludeRange(range: CharRange): List<CharRange> {
    val result = ArrayList<CharRange>()
    for (thisRange in this) {
        result.addAll(thisRange - range)
    }

    return result
}

internal fun List<CharRange>.excludeRanges(ranges: List<CharRange>): List<CharRange> {
    if (ranges.isEmpty()) {
        return this
    }

    var list = this
    for (range in ranges) {
        list = list.excludeRange(range)
    }

    return list.sortedBy {
        it.first
    }.optimizeRanges()
}

internal val IntRange.debugString: String
    get() {
        if (this.last == Int.MAX_VALUE) {
            return "$first,max"
        } else {
            return "$first,$last"
        }
    }

Compiled from "RangeExtensions.kt"
public final class com.kotlinspirit.ext.RangeExtensionsKt {
  public static final java.util.List<kotlin.ranges.CharRange> minus(kotlin.ranges.CharRange, kotlin.ranges.CharRange);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String range
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      16: aload_0
      17: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      20: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      23: ifgt          44
      26: aload_1
      27: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      30: aload_0
      31: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      34: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      37: iflt          44
      40: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      43: areturn
      44: aload_1
      45: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      48: aload_0
      49: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      52: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      55: ifle          119
      58: aload_1
      59: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      62: aload_0
      63: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      66: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      69: ifge          119
      72: iconst_2
      73: anewarray     #20                 // class kotlin/ranges/CharRange
      76: astore_2
      77: aload_2
      78: iconst_0
      79: aload_0
      80: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      83: aload_1
      84: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      87: invokestatic  #43                 // Method kotlin/ranges/RangesKt.until:(CC)Lkotlin/ranges/CharRange;
      90: aastore
      91: aload_2
      92: iconst_1
      93: new           #20                 // class kotlin/ranges/CharRange
      96: dup
      97: aload_1
      98: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     101: iconst_1
     102: iadd
     103: i2c
     104: aload_0
     105: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     108: invokespecial #47                 // Method kotlin/ranges/CharRange."<init>":(CC)V
     111: aastore
     112: aload_2
     113: invokestatic  #51                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     116: goto          234
     119: aload_1
     120: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     123: aload_0
     124: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     127: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     130: ifgt          171
     133: aload_1
     134: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     137: aload_0
     138: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     141: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     144: iflt          171
     147: new           #20                 // class kotlin/ranges/CharRange
     150: dup
     151: aload_1
     152: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     155: iconst_1
     156: iadd
     157: i2c
     158: aload_0
     159: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     162: invokespecial #47                 // Method kotlin/ranges/CharRange."<init>":(CC)V
     165: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     168: goto          234
     171: aload_1
     172: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     175: aload_0
     176: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     179: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     182: ifle          230
     185: aload_1
     186: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     189: aload_0
     190: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     193: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     196: iflt          230
     199: aload_1
     200: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     203: aload_0
     204: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     207: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     210: ifgt          230
     213: aload_0
     214: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     217: aload_1
     218: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     221: invokestatic  #43                 // Method kotlin/ranges/RangesKt.until:(CC)Lkotlin/ranges/CharRange;
     224: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     227: goto          234
     230: aload_0
     231: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     234: areturn

  public static final java.util.List<kotlin.ranges.CharRange> plus(kotlin.ranges.CharRange, kotlin.ranges.CharRange);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String range
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: nop
      13: aload_1
      14: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      17: aload_0
      18: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      21: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      24: ifgt          48
      27: aload_1
      28: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      31: aload_0
      32: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      35: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      38: iflt          48
      41: aload_1
      42: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      45: goto          233
      48: aload_0
      49: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      52: aload_1
      53: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      56: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      59: ifgt          83
      62: aload_0
      63: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      66: aload_1
      67: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
      70: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      73: iflt          83
      76: aload_0
      77: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      80: goto          233
      83: aload_1
      84: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      87: aload_0
      88: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
      91: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      94: ifgt          149
      97: aload_1
      98: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     101: aload_0
     102: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     105: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     108: ifgt          149
     111: aload_1
     112: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     115: aload_0
     116: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     119: iconst_1
     120: isub
     121: i2c
     122: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     125: iflt          149
     128: new           #20                 // class kotlin/ranges/CharRange
     131: dup
     132: aload_1
     133: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     136: aload_0
     137: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     140: invokespecial #47                 // Method kotlin/ranges/CharRange."<init>":(CC)V
     143: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     146: goto          233
     149: aload_1
     150: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     153: aload_0
     154: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     157: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     160: ifle          215
     163: aload_1
     164: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     167: aload_0
     168: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     171: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     174: iflt          215
     177: aload_1
     178: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     181: aload_0
     182: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     185: iconst_1
     186: iadd
     187: i2c
     188: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     191: ifgt          215
     194: new           #20                 // class kotlin/ranges/CharRange
     197: dup
     198: aload_0
     199: invokevirtual #24                 // Method kotlin/ranges/CharRange.getFirst:()C
     202: aload_1
     203: invokevirtual #31                 // Method kotlin/ranges/CharRange.getLast:()C
     206: invokespecial #47                 // Method kotlin/ranges/CharRange."<init>":(CC)V
     209: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     212: goto          233
     215: iconst_2
     216: anewarray     #20                 // class kotlin/ranges/CharRange
     219: astore_2
     220: aload_2
     221: iconst_0
     222: aload_0
     223: aastore
     224: aload_2
     225: iconst_1
     226: aload_1
     227: aastore
     228: aload_2
     229: invokestatic  #51                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     232: areturn
     233: areturn

  private static final java.util.List<kotlin.ranges.CharRange> optimizeRanges(java.util.List<kotlin.ranges.CharRange>);
    Code:
       0: aload_0
       1: invokeinterface #67,  1           // InterfaceMethod java/util/List.size:()I
       6: iconst_1
       7: if_icmpgt     12
      10: aload_0
      11: areturn
      12: iconst_1
      13: anewarray     #20                 // class kotlin/ranges/CharRange
      16: astore_2
      17: aload_2
      18: iconst_0
      19: aload_0
      20: iconst_0
      21: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      26: aastore
      27: aload_2
      28: invokestatic  #75                 // Method kotlin/collections/CollectionsKt.arrayListOf:([Ljava/lang/Object;)Ljava/util/ArrayList;
      31: astore_1
      32: iconst_1
      33: istore_2
      34: aload_0
      35: invokeinterface #67,  1           // InterfaceMethod java/util/List.size:()I
      40: istore_3
      41: iload_2
      42: iload_3
      43: if_icmpge     86
      46: aload_1
      47: aload_1
      48: invokevirtual #81                 // Method java/util/ArrayList.removeLast:()Ljava/lang/Object;
      51: dup
      52: ldc           #83                 // String removeLast(...)
      54: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      57: checkcast     #20                 // class kotlin/ranges/CharRange
      60: aload_0
      61: iload_2
      62: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #20                 // class kotlin/ranges/CharRange
      70: invokestatic  #88                 // Method plus:(Lkotlin/ranges/CharRange;Lkotlin/ranges/CharRange;)Ljava/util/List;
      73: checkcast     #90                 // class java/util/Collection
      76: invokevirtual #94                 // Method java/util/ArrayList.addAll:(Ljava/util/Collection;)Z
      79: pop
      80: iinc          2, 1
      83: goto          41
      86: aload_1
      87: checkcast     #58                 // class java/util/List
      90: areturn

  public static final java.util.List<kotlin.ranges.CharRange> includeRanges(java.util.List<kotlin.ranges.CharRange>, java.util.List<kotlin.ranges.CharRange>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #105                // String ranges
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #90                 // class java/util/Collection
      16: aload_1
      17: checkcast     #107                // class java/lang/Iterable
      20: invokestatic  #110                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
      23: checkcast     #107                // class java/lang/Iterable
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_2
      30: new           #112                // class com/kotlinspirit/ext/RangeExtensionsKt$includeRanges$$inlined$sortedBy$1
      33: dup
      34: invokespecial #115                // Method com/kotlinspirit/ext/RangeExtensionsKt$includeRanges$$inlined$sortedBy$1."<init>":()V
      37: checkcast     #117                // class java/util/Comparator
      40: invokestatic  #121                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      43: invokestatic  #123                // Method optimizeRanges:(Ljava/util/List;)Ljava/util/List;
      46: areturn

  public static final java.util.List<kotlin.ranges.CharRange> excludeRange(java.util.List<kotlin.ranges.CharRange>, kotlin.ranges.CharRange);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String range
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #77                 // class java/util/ArrayList
      15: dup
      16: invokespecial #131                // Method java/util/ArrayList."<init>":()V
      19: astore_2
      20: aload_0
      21: invokeinterface #135,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      26: astore_3
      27: aload_3
      28: invokeinterface #141,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          64
      36: aload_3
      37: invokeinterface #144,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: checkcast     #20                 // class kotlin/ranges/CharRange
      45: astore        4
      47: aload_2
      48: aload         4
      50: aload_1
      51: invokestatic  #146                // Method minus:(Lkotlin/ranges/CharRange;Lkotlin/ranges/CharRange;)Ljava/util/List;
      54: checkcast     #90                 // class java/util/Collection
      57: invokevirtual #94                 // Method java/util/ArrayList.addAll:(Ljava/util/Collection;)Z
      60: pop
      61: goto          27
      64: aload_2
      65: checkcast     #58                 // class java/util/List
      68: areturn

  public static final java.util.List<kotlin.ranges.CharRange> excludeRanges(java.util.List<kotlin.ranges.CharRange>, java.util.List<kotlin.ranges.CharRange>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #105                // String ranges
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokeinterface #152,  1          // InterfaceMethod java/util/List.isEmpty:()Z
      18: ifeq          23
      21: aload_0
      22: areturn
      23: aload_0
      24: astore_2
      25: aload_1
      26: invokeinterface #135,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      31: astore_3
      32: aload_3
      33: invokeinterface #141,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      38: ifeq          62
      41: aload_3
      42: invokeinterface #144,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: checkcast     #20                 // class kotlin/ranges/CharRange
      50: astore        4
      52: aload_2
      53: aload         4
      55: invokestatic  #154                // Method excludeRange:(Ljava/util/List;Lkotlin/ranges/CharRange;)Ljava/util/List;
      58: astore_2
      59: goto          32
      62: aload_2
      63: checkcast     #107                // class java/lang/Iterable
      66: astore_3
      67: iconst_0
      68: istore        4
      70: aload_3
      71: new           #156                // class com/kotlinspirit/ext/RangeExtensionsKt$excludeRanges$$inlined$sortedBy$1
      74: dup
      75: invokespecial #157                // Method com/kotlinspirit/ext/RangeExtensionsKt$excludeRanges$$inlined$sortedBy$1."<init>":()V
      78: checkcast     #117                // class java/util/Comparator
      81: invokestatic  #121                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      84: invokestatic  #123                // Method optimizeRanges:(Ljava/util/List;)Ljava/util/List;
      87: areturn

  public static final java.lang.String getDebugString(kotlin.ranges.IntRange);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #165                // Method kotlin/ranges/IntRange.getLast:()I
      10: ldc           #166                // int 2147483647
      12: if_icmpne     38
      15: new           #168                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #169                // Method java/lang/StringBuilder."<init>":()V
      22: aload_0
      23: invokevirtual #171                // Method kotlin/ranges/IntRange.getFirst:()I
      26: invokevirtual #175                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      29: ldc           #177                // String ,max
      31: invokevirtual #180                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      34: invokevirtual #184                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      37: areturn
      38: new           #168                // class java/lang/StringBuilder
      41: dup
      42: invokespecial #169                // Method java/lang/StringBuilder."<init>":()V
      45: aload_0
      46: invokevirtual #171                // Method kotlin/ranges/IntRange.getFirst:()I
      49: invokevirtual #175                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      52: bipush        44
      54: invokevirtual #187                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      57: aload_0
      58: invokevirtual #165                // Method kotlin/ranges/IntRange.getLast:()I
      61: invokevirtual #175                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      64: invokevirtual #184                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      67: areturn
}

Compiled from "Comparisons.kt"
public final class com.kotlinspirit.ext.RangeExtensionsKt$includeRanges$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public com.kotlinspirit.ext.RangeExtensionsKt$includeRanges$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/ranges/CharRange
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/ranges/CharRange.getFirst:()C
      12: invokestatic  #33                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class kotlin/ranges/CharRange
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/ranges/CharRange.getFirst:()C
      32: invokestatic  #33                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "Comparisons.kt"
public final class com.kotlinspirit.ext.RangeExtensionsKt$excludeRanges$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public com.kotlinspirit.ext.RangeExtensionsKt$excludeRanges$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/ranges/CharRange
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/ranges/CharRange.getFirst:()C
      12: invokestatic  #33                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class kotlin/ranges/CharRange
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/ranges/CharRange.getFirst:()C
      32: invokestatic  #33                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}


package org.motivesearch.csma

data class MotiveUnit(val name: String)

data class MotivePosition(val position: Int, val length: Int)

data class Motive(val positions: List<MotivePosition>, val frequency: Int, val sequence: List<MotiveUnit>) {
    companion object {
        fun fromPositions(positions: List<MotivePosition>, sequence: List<MotiveUnit>) =
            Motive(positions, positions.size, sequence)
    }
}

class MotiveGenerator {

    fun generateMotives(
        sequence: List<MotiveUnit>,
        minFrequency: Int,
        maxGap: Int,
        minLength: Int,
        maxLength: Int
    ): List<Motive> {
        val basicMotives = getBasicMotives(sequence, minFrequency)

        var motivesOfIteration = basicMotives

        var motivesOfAllIterations = emptyList<Motive>()
        while (motivesOfIteration.isNotEmpty()) {
            motivesOfIteration =
                motiveOfIteration(motivesOfIteration, basicMotives, minFrequency, maxLength, maxGap)
            motivesOfAllIterations = motivesOfAllIterations + motivesOfIteration.filter { it.sequence.size >= minLength}
        }

        return motivesOfAllIterations
    }

    private fun motiveOfIteration(
        motivesOfLastIteration: List<Motive>,
        baseMotives: List<Motive>,
        minFrequency: Int,
        maxLength: Int,
        maxGap: Int
    ): List<Motive> {
        val motivesOfNextIteration = motivesOfLastIteration.map { motiveOfIteration ->
            val frequentPosition = getFrequentPosition(motiveOfIteration, minFrequency)
            val candidateExtensions = generateCandidateExtension(baseMotives, frequentPosition)

            candidateExtensions.map { candidateExtension ->
                mergeMotives(motiveOfIteration, candidateExtension, maxGap, maxLength)
            }
        }.flatten()

        return filterMotives(motivesOfNextIteration, minFrequency, maxLength)
    }

    fun getBasicMotives(sequence: List<MotiveUnit>, minFrequency: Int): List<Motive> {
        val basicMotiveUnits = sequence.toSet()

        val basicMotives =
            basicMotiveUnits.map { it to Motive(emptyList(), 0, listOf(it)) }
                .toMap().toMutableMap()

        sequence.forEachIndexed { index, motiveUnit ->
            val motive = basicMotives[motiveUnit]!!
            val newPositions = motive.positions.toMutableList()
            newPositions.add(MotivePosition(index, 1))
            basicMotives[motiveUnit] = motive.copy(positions = newPositions, frequency = motive.frequency + 1)
        }

        val basicMotivesAboveMinFrequency = basicMotives.filter { it.value.frequency >= minFrequency }

        return basicMotivesAboveMinFrequency.values.toList()
    }

    fun getMotiveUnits(sequence: String): List<MotiveUnit> {
        val uniqueValues = sequence.split(",")

        return uniqueValues.map { MotiveUnit(it) }
    }

    fun getFrequentPosition(motive: Motive, minFrequency: Int): Int {
        if (motive.frequency < minFrequency) throw IllegalArgumentException("Motiv frequency is less than minFrequency")

        val position = motive.positions[minFrequency - 1]
        return position.position + position.length
    }

    fun generateCandidateExtension(baseMotives: List<Motive>, frequentPosition: Int): List<Motive> {
        return baseMotives.filter { baseMotive ->
            baseMotive.positions.any { position -> position.position >= frequentPosition - 1 }
        }
    }

    fun mergeMotives(motive: Motive, candidateExtension: Motive, maxGap: Int, maxLength: Int): Motive {
        val newSequence = motive.sequence + candidateExtension.sequence

        val newPositions = motive.positions.map { position ->
            val nextCandidatePosition = candidateExtension.positions.filter { candidatePosition ->
                val notToLargeGap = candidatePosition.position - (position.position + position.length) <= maxGap
                val afterPosition = candidatePosition.position >= (position.position + position.length)
                val notToLong = candidatePosition.position + candidatePosition.length - position.position <= maxLength
                notToLargeGap && afterPosition && notToLong
            }.firstOrNull()

            if (nextCandidatePosition != null) {
                MotivePosition(position.position, position.length + nextCandidatePosition.length)
            } else {
                null
            }
        }.filterNotNull()

        return motive.copy(positions = newPositions, frequency = newPositions.size, sequence = newSequence)
    }

    private fun filterMotives(motives: List<Motive>, minFrequency: Int, maxLength: Int): List<Motive> {
        return motives.filter { it.frequency >= minFrequency && it.sequence.size <= maxLength }
    }

}

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

  public final java.util.List<org.motivesearch.csma.Motive> generateMotives(java.util.List<org.motivesearch.csma.MotiveUnit>, int, int, int, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String sequence
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iload_2
       9: invokevirtual #26                 // Method getBasicMotives:(Ljava/util/List;I)Ljava/util/List;
      12: astore        6
      14: aload         6
      16: astore        7
      18: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      21: astore        8
      23: aload         7
      25: checkcast     #34                 // class java/util/Collection
      28: invokeinterface #38,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      33: ifne          40
      36: iconst_1
      37: goto          41
      40: iconst_0
      41: ifeq          188
      44: aload_0
      45: aload         7
      47: aload         6
      49: iload_2
      50: iload         5
      52: iload_3
      53: invokespecial #42                 // Method motiveOfIteration:(Ljava/util/List;Ljava/util/List;III)Ljava/util/List;
      56: astore        7
      58: aload         8
      60: checkcast     #34                 // class java/util/Collection
      63: aload         7
      65: checkcast     #44                 // class java/lang/Iterable
      68: astore        9
      70: astore        18
      72: iconst_0
      73: istore        10
      75: aload         9
      77: astore        11
      79: new           #46                 // class java/util/ArrayList
      82: dup
      83: invokespecial #47                 // Method java/util/ArrayList."<init>":()V
      86: checkcast     #34                 // class java/util/Collection
      89: astore        12
      91: iconst_0
      92: istore        13
      94: aload         11
      96: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     101: astore        14
     103: aload         14
     105: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     110: ifeq          168
     113: aload         14
     115: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        15
     122: aload         15
     124: checkcast     #62                 // class org/motivesearch/csma/Motive
     127: astore        16
     129: iconst_0
     130: istore        17
     132: aload         16
     134: invokevirtual #65                 // Method org/motivesearch/csma/Motive.getSequence:()Ljava/util/List;
     137: invokeinterface #71,  1           // InterfaceMethod java/util/List.size:()I
     142: iload         4
     144: if_icmplt     151
     147: iconst_1
     148: goto          152
     151: iconst_0
     152: ifeq          103
     155: aload         12
     157: aload         15
     159: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     164: pop
     165: goto          103
     168: aload         12
     170: checkcast     #67                 // class java/util/List
     173: nop
     174: aload         18
     176: swap
     177: checkcast     #44                 // class java/lang/Iterable
     180: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     183: astore        8
     185: goto          23
     188: aload         8
     190: areturn

  private final java.util.List<org.motivesearch.csma.Motive> motiveOfIteration(java.util.List<org.motivesearch.csma.Motive>, java.util.List<org.motivesearch.csma.Motive>, int, int, int);
    Code:
       0: aload_1
       1: checkcast     #44                 // class java/lang/Iterable
       4: astore        7
       6: iconst_0
       7: istore        8
       9: aload         7
      11: astore        9
      13: new           #46                 // class java/util/ArrayList
      16: dup
      17: aload         7
      19: bipush        10
      21: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      24: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      27: checkcast     #34                 // class java/util/Collection
      30: astore        10
      32: iconst_0
      33: istore        11
      35: aload         9
      37: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        12
      44: aload         12
      46: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          216
      54: aload         12
      56: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        13
      63: aload         10
      65: aload         13
      67: checkcast     #62                 // class org/motivesearch/csma/Motive
      70: astore        14
      72: astore        28
      74: iconst_0
      75: istore        15
      77: aload_0
      78: aload         14
      80: iload_3
      81: invokevirtual #112                // Method getFrequentPosition:(Lorg/motivesearch/csma/Motive;I)I
      84: istore        16
      86: aload_0
      87: aload_2
      88: iload         16
      90: invokevirtual #115                // Method generateCandidateExtension:(Ljava/util/List;I)Ljava/util/List;
      93: astore        17
      95: aload         17
      97: checkcast     #44                 // class java/lang/Iterable
     100: astore        18
     102: iconst_0
     103: istore        19
     105: aload         18
     107: astore        20
     109: new           #46                 // class java/util/ArrayList
     112: dup
     113: aload         18
     115: bipush        10
     117: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     120: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
     123: checkcast     #34                 // class java/util/Collection
     126: astore        21
     128: iconst_0
     129: istore        22
     131: aload         20
     133: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     138: astore        23
     140: aload         23
     142: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     147: ifeq          197
     150: aload         23
     152: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     157: astore        24
     159: aload         21
     161: aload         24
     163: checkcast     #62                 // class org/motivesearch/csma/Motive
     166: astore        25
     168: astore        26
     170: iconst_0
     171: istore        27
     173: aload_0
     174: aload         14
     176: aload         25
     178: iload         5
     180: iload         4
     182: invokevirtual #119                // Method mergeMotives:(Lorg/motivesearch/csma/Motive;Lorg/motivesearch/csma/Motive;II)Lorg/motivesearch/csma/Motive;
     185: aload         26
     187: swap
     188: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     193: pop
     194: goto          140
     197: aload         21
     199: checkcast     #67                 // class java/util/List
     202: nop
     203: nop
     204: aload         28
     206: swap
     207: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     212: pop
     213: goto          44
     216: aload         10
     218: checkcast     #67                 // class java/util/List
     221: nop
     222: checkcast     #44                 // class java/lang/Iterable
     225: invokestatic  #123                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     228: astore        6
     230: aload_0
     231: aload         6
     233: iload_3
     234: iload         4
     236: invokespecial #127                // Method filterMotives:(Ljava/util/List;II)Ljava/util/List;
     239: areturn

  public final java.util.List<org.motivesearch.csma.Motive> getBasicMotives(java.util.List<org.motivesearch.csma.MotiveUnit>, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String sequence
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #44                 // class java/lang/Iterable
      10: invokestatic  #145                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
      13: astore_3
      14: aload_3
      15: checkcast     #44                 // class java/lang/Iterable
      18: astore        5
      20: iconst_0
      21: istore        6
      23: aload         5
      25: astore        7
      27: new           #46                 // class java/util/ArrayList
      30: dup
      31: aload         5
      33: bipush        10
      35: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      38: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      41: checkcast     #34                 // class java/util/Collection
      44: astore        8
      46: iconst_0
      47: istore        9
      49: aload         7
      51: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        10
      58: aload         10
      60: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          124
      68: aload         10
      70: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        11
      77: aload         8
      79: aload         11
      81: checkcast     #147                // class org/motivesearch/csma/MotiveUnit
      84: astore        12
      86: astore        16
      88: iconst_0
      89: istore        13
      91: aload         12
      93: new           #62                 // class org/motivesearch/csma/Motive
      96: dup
      97: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     100: iconst_0
     101: aload         12
     103: invokestatic  #151                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     106: invokespecial #154                // Method org/motivesearch/csma/Motive."<init>":(Ljava/util/List;ILjava/util/List;)V
     109: invokestatic  #160                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     112: aload         16
     114: swap
     115: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     120: pop
     121: goto          58
     124: aload         8
     126: checkcast     #67                 // class java/util/List
     129: nop
     130: checkcast     #44                 // class java/lang/Iterable
     133: invokestatic  #166                // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     136: invokestatic  #170                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     139: astore        4
     141: aload_1
     142: checkcast     #44                 // class java/lang/Iterable
     145: astore        5
     147: iconst_0
     148: istore        6
     150: iconst_0
     151: istore        7
     153: aload         5
     155: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     160: astore        8
     162: aload         8
     164: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          291
     172: aload         8
     174: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     179: astore        9
     181: iload         7
     183: iinc          7, 1
     186: istore        10
     188: iload         10
     190: ifge          196
     193: invokestatic  #173                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     196: iload         10
     198: aload         9
     200: checkcast     #147                // class org/motivesearch/csma/MotiveUnit
     203: astore        11
     205: istore        12
     207: iconst_0
     208: istore        13
     210: aload         4
     212: aload         11
     214: invokeinterface #179,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     219: dup
     220: invokestatic  #183                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     223: checkcast     #62                 // class org/motivesearch/csma/Motive
     226: astore        14
     228: aload         14
     230: invokevirtual #186                // Method org/motivesearch/csma/Motive.getPositions:()Ljava/util/List;
     233: checkcast     #34                 // class java/util/Collection
     236: invokestatic  #190                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     239: astore        15
     241: aload         15
     243: new           #192                // class org/motivesearch/csma/MotivePosition
     246: dup
     247: iload         12
     249: iconst_1
     250: invokespecial #195                // Method org/motivesearch/csma/MotivePosition."<init>":(II)V
     253: invokeinterface #196,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     258: pop
     259: aload         4
     261: aload         11
     263: aload         14
     265: aload         15
     267: aload         14
     269: invokevirtual #199                // Method org/motivesearch/csma/Motive.getFrequency:()I
     272: iconst_1
     273: iadd
     274: aconst_null
     275: iconst_4
     276: aconst_null
     277: invokestatic  #203                // Method org/motivesearch/csma/Motive.copy$default:(Lorg/motivesearch/csma/Motive;Ljava/util/List;ILjava/util/List;ILjava/lang/Object;)Lorg/motivesearch/csma/Motive;
     280: invokeinterface #207,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     285: pop
     286: nop
     287: nop
     288: goto          162
     291: nop
     292: aload         4
     294: astore        6
     296: iconst_0
     297: istore        7
     299: aload         6
     301: astore        8
     303: new           #209                // class java/util/LinkedHashMap
     306: dup
     307: invokespecial #210                // Method java/util/LinkedHashMap."<init>":()V
     310: checkcast     #175                // class java/util/Map
     313: astore        9
     315: iconst_0
     316: istore        10
     318: aload         8
     320: invokeinterface #214,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     325: invokeinterface #217,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     330: astore        11
     332: aload         11
     334: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     339: ifeq          411
     342: aload         11
     344: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     349: checkcast     #219                // class java/util/Map$Entry
     352: astore        12
     354: aload         12
     356: astore        13
     358: iconst_0
     359: istore        14
     361: aload         13
     363: invokeinterface #222,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     368: checkcast     #62                 // class org/motivesearch/csma/Motive
     371: invokevirtual #199                // Method org/motivesearch/csma/Motive.getFrequency:()I
     374: iload_2
     375: if_icmplt     382
     378: iconst_1
     379: goto          383
     382: iconst_0
     383: ifeq          332
     386: aload         9
     388: aload         12
     390: invokeinterface #225,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     395: aload         12
     397: invokeinterface #222,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     402: invokeinterface #207,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     407: pop
     408: goto          332
     411: aload         9
     413: nop
     414: astore        5
     416: aload         5
     418: invokeinterface #229,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     423: checkcast     #44                 // class java/lang/Iterable
     426: invokestatic  #232                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     429: areturn

  public final java.util.List<org.motivesearch.csma.MotiveUnit> getMotiveUnits(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #16                 // String sequence
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #254                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #256                // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc_w         #258                // String ,
      20: aastore
      21: aload_3
      22: iconst_0
      23: iconst_0
      24: bipush        6
      26: aconst_null
      27: invokestatic  #264                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      30: astore_2
      31: aload_2
      32: checkcast     #44                 // class java/lang/Iterable
      35: astore_3
      36: iconst_0
      37: istore        4
      39: aload_3
      40: astore        5
      42: new           #46                 // class java/util/ArrayList
      45: dup
      46: aload_3
      47: bipush        10
      49: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      52: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      55: checkcast     #34                 // class java/util/Collection
      58: astore        6
      60: iconst_0
      61: istore        7
      63: aload         5
      65: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      70: astore        8
      72: aload         8
      74: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      79: ifeq          126
      82: aload         8
      84: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      89: astore        9
      91: aload         6
      93: aload         9
      95: checkcast     #256                // class java/lang/String
      98: astore        10
     100: astore        12
     102: iconst_0
     103: istore        11
     105: new           #147                // class org/motivesearch/csma/MotiveUnit
     108: dup
     109: aload         10
     111: invokespecial #267                // Method org/motivesearch/csma/MotiveUnit."<init>":(Ljava/lang/String;)V
     114: aload         12
     116: swap
     117: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: goto          72
     126: aload         6
     128: checkcast     #67                 // class java/util/List
     131: nop
     132: areturn

  public final int getFrequentPosition(org.motivesearch.csma.Motive, int);
    Code:
       0: aload_1
       1: ldc_w         #271                // String motive
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #199                // Method org/motivesearch/csma/Motive.getFrequency:()I
      11: iload_2
      12: if_icmpge     26
      15: new           #273                // class java/lang/IllegalArgumentException
      18: dup
      19: ldc_w         #275                // String Motiv frequency is less than minFrequency
      22: invokespecial #276                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      25: athrow
      26: aload_1
      27: invokevirtual #186                // Method org/motivesearch/csma/Motive.getPositions:()Ljava/util/List;
      30: iload_2
      31: iconst_1
      32: isub
      33: invokeinterface #279,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: checkcast     #192                // class org/motivesearch/csma/MotivePosition
      41: astore_3
      42: aload_3
      43: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
      46: aload_3
      47: invokevirtual #285                // Method org/motivesearch/csma/MotivePosition.getLength:()I
      50: iadd
      51: ireturn

  public final java.util.List<org.motivesearch.csma.Motive> generateCandidateExtension(java.util.List<org.motivesearch.csma.Motive>, int);
    Code:
       0: aload_1
       1: ldc_w         #289                // String baseMotives
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: checkcast     #44                 // class java/lang/Iterable
      11: astore_3
      12: iconst_0
      13: istore        4
      15: aload_3
      16: astore        5
      18: new           #46                 // class java/util/ArrayList
      21: dup
      22: invokespecial #47                 // Method java/util/ArrayList."<init>":()V
      25: checkcast     #34                 // class java/util/Collection
      28: astore        6
      30: iconst_0
      31: istore        7
      33: aload         5
      35: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        8
      42: aload         8
      44: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          188
      52: aload         8
      54: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        9
      61: aload         9
      63: checkcast     #62                 // class org/motivesearch/csma/Motive
      66: astore        10
      68: iconst_0
      69: istore        11
      71: aload         10
      73: invokevirtual #186                // Method org/motivesearch/csma/Motive.getPositions:()Ljava/util/List;
      76: checkcast     #44                 // class java/lang/Iterable
      79: astore        12
      81: iconst_0
      82: istore        13
      84: aload         12
      86: instanceof    #34                 // class java/util/Collection
      89: ifeq          109
      92: aload         12
      94: checkcast     #34                 // class java/util/Collection
      97: invokeinterface #38,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     102: ifeq          109
     105: iconst_0
     106: goto          171
     109: aload         12
     111: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        14
     118: aload         14
     120: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          170
     128: aload         14
     130: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        15
     137: aload         15
     139: checkcast     #192                // class org/motivesearch/csma/MotivePosition
     142: astore        16
     144: iconst_0
     145: istore        17
     147: aload         16
     149: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     152: iload_2
     153: iconst_1
     154: isub
     155: if_icmplt     162
     158: iconst_1
     159: goto          163
     162: iconst_0
     163: ifeq          118
     166: iconst_1
     167: goto          171
     170: iconst_0
     171: nop
     172: ifeq          42
     175: aload         6
     177: aload         9
     179: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          42
     188: aload         6
     190: checkcast     #67                 // class java/util/List
     193: nop
     194: areturn

  public final org.motivesearch.csma.Motive mergeMotives(org.motivesearch.csma.Motive, org.motivesearch.csma.Motive, int, int);
    Code:
       0: aload_1
       1: ldc_w         #271                // String motive
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: ldc_w         #296                // String candidateExtension
      11: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_1
      15: invokevirtual #65                 // Method org/motivesearch/csma/Motive.getSequence:()Ljava/util/List;
      18: checkcast     #34                 // class java/util/Collection
      21: aload_2
      22: invokevirtual #65                 // Method org/motivesearch/csma/Motive.getSequence:()Ljava/util/List;
      25: checkcast     #44                 // class java/lang/Iterable
      28: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
      31: astore        5
      33: aload_1
      34: invokevirtual #186                // Method org/motivesearch/csma/Motive.getPositions:()Ljava/util/List;
      37: checkcast     #44                 // class java/lang/Iterable
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         7
      47: astore        9
      49: new           #46                 // class java/util/ArrayList
      52: dup
      53: aload         7
      55: bipush        10
      57: invokestatic  #105                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      60: invokespecial #108                // Method java/util/ArrayList."<init>":(I)V
      63: checkcast     #34                 // class java/util/Collection
      66: astore        10
      68: iconst_0
      69: istore        11
      71: aload         9
      73: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      78: astore        12
      80: aload         12
      82: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          360
      90: aload         12
      92: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      97: astore        13
      99: aload         10
     101: aload         13
     103: checkcast     #192                // class org/motivesearch/csma/MotivePosition
     106: astore        14
     108: astore        29
     110: iconst_0
     111: istore        15
     113: aload_2
     114: invokevirtual #186                // Method org/motivesearch/csma/Motive.getPositions:()Ljava/util/List;
     117: checkcast     #44                 // class java/lang/Iterable
     120: astore        16
     122: iconst_0
     123: istore        17
     125: aload         16
     127: astore        18
     129: new           #46                 // class java/util/ArrayList
     132: dup
     133: invokespecial #47                 // Method java/util/ArrayList."<init>":()V
     136: checkcast     #34                 // class java/util/Collection
     139: astore        19
     141: iconst_0
     142: istore        20
     144: aload         18
     146: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     151: astore        21
     153: aload         21
     155: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     160: ifeq          301
     163: aload         21
     165: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: astore        22
     172: aload         22
     174: checkcast     #192                // class org/motivesearch/csma/MotivePosition
     177: astore        23
     179: iconst_0
     180: istore        24
     182: aload         23
     184: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     187: aload         14
     189: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     192: aload         14
     194: invokevirtual #285                // Method org/motivesearch/csma/MotivePosition.getLength:()I
     197: iadd
     198: isub
     199: iload_3
     200: if_icmpgt     207
     203: iconst_1
     204: goto          208
     207: iconst_0
     208: istore        25
     210: aload         23
     212: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     215: aload         14
     217: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     220: aload         14
     222: invokevirtual #285                // Method org/motivesearch/csma/MotivePosition.getLength:()I
     225: iadd
     226: if_icmplt     233
     229: iconst_1
     230: goto          234
     233: iconst_0
     234: istore        26
     236: aload         23
     238: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     241: aload         23
     243: invokevirtual #285                // Method org/motivesearch/csma/MotivePosition.getLength:()I
     246: iadd
     247: aload         14
     249: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     252: isub
     253: iload         4
     255: if_icmpgt     262
     258: iconst_1
     259: goto          263
     262: iconst_0
     263: istore        27
     265: iload         25
     267: ifeq          284
     270: iload         26
     272: ifeq          284
     275: iload         27
     277: ifeq          284
     280: iconst_1
     281: goto          285
     284: iconst_0
     285: ifeq          153
     288: aload         19
     290: aload         22
     292: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     297: pop
     298: goto          153
     301: aload         19
     303: checkcast     #67                 // class java/util/List
     306: nop
     307: invokestatic  #300                // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/util/List;)Ljava/lang/Object;
     310: checkcast     #192                // class org/motivesearch/csma/MotivePosition
     313: astore        28
     315: aload         28
     317: ifnull        346
     320: new           #192                // class org/motivesearch/csma/MotivePosition
     323: dup
     324: aload         14
     326: invokevirtual #282                // Method org/motivesearch/csma/MotivePosition.getPosition:()I
     329: aload         14
     331: invokevirtual #285                // Method org/motivesearch/csma/MotivePosition.getLength:()I
     334: aload         28
     336: invokevirtual #285                // Method org/motivesearch/csma/MotivePosition.getLength:()I
     339: iadd
     340: invokespecial #195                // Method org/motivesearch/csma/MotivePosition."<init>":(II)V
     343: goto          347
     346: aconst_null
     347: nop
     348: aload         29
     350: swap
     351: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     356: pop
     357: goto          80
     360: aload         10
     362: checkcast     #67                 // class java/util/List
     365: nop
     366: checkcast     #44                 // class java/lang/Iterable
     369: invokestatic  #303                // Method kotlin/collections/CollectionsKt.filterNotNull:(Ljava/lang/Iterable;)Ljava/util/List;
     372: astore        6
     374: aload_1
     375: aload         6
     377: aload         6
     379: invokeinterface #71,  1           // InterfaceMethod java/util/List.size:()I
     384: aload         5
     386: invokevirtual #307                // Method org/motivesearch/csma/Motive.copy:(Ljava/util/List;ILjava/util/List;)Lorg/motivesearch/csma/Motive;
     389: areturn

  private final java.util.List<org.motivesearch.csma.Motive> filterMotives(java.util.List<org.motivesearch.csma.Motive>, int, int);
    Code:
       0: aload_1
       1: checkcast     #44                 // class java/lang/Iterable
       4: astore        4
       6: iconst_0
       7: istore        5
       9: aload         4
      11: astore        6
      13: new           #46                 // class java/util/ArrayList
      16: dup
      17: invokespecial #47                 // Method java/util/ArrayList."<init>":()V
      20: checkcast     #34                 // class java/util/Collection
      23: astore        7
      25: iconst_0
      26: istore        8
      28: aload         6
      30: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        9
      37: aload         9
      39: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          110
      47: aload         9
      49: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        10
      56: aload         10
      58: checkcast     #62                 // class org/motivesearch/csma/Motive
      61: astore        11
      63: iconst_0
      64: istore        12
      66: aload         11
      68: invokevirtual #199                // Method org/motivesearch/csma/Motive.getFrequency:()I
      71: iload_2
      72: if_icmplt     93
      75: aload         11
      77: invokevirtual #65                 // Method org/motivesearch/csma/Motive.getSequence:()Ljava/util/List;
      80: invokeinterface #71,  1           // InterfaceMethod java/util/List.size:()I
      85: iload_3
      86: if_icmpgt     93
      89: iconst_1
      90: goto          94
      93: iconst_0
      94: ifeq          37
      97: aload         7
      99: aload         10
     101: invokeinterface #75,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: goto          37
     110: aload         7
     112: checkcast     #67                 // class java/util/List
     115: nop
     116: areturn
}


package com.weiliange.algorithm

import kotlin.math.pow

/**
 * @author : WilliamYang
 * @date : 2022/3/8 11:36
 * @description : 两数相加
 *
 * 给你两个 非空 的链表，表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的，并且每个节点只能存储 一位 数字。
 * 请你将两个数相加，并以相同形式返回一个表示和的链表。
 * 你可以假设除了数字 0 之外，这两个数都不会以 0 开头。
 *
 * 示例 1：
 * 输入：l1 = [2,4,3], l2 = [5,6,4]
 * 输出：[7,0,8]
 * 解释：342 + 465 = 807.
 *
 * 示例 2：
 * 输入：l1 = [0], l2 = [0]
 * 输出：[0]
 *
 * 示例 3：
 * 输入：l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
 * 输出：[8,9,9,9,0,0,0,1]
 *
 * 提示：
 * 每个链表中的节点数在范围 [1, 100] 内
 * 0 <= Node.val <= 9
 * 题目数据保证列表表示的数字不含前导零
 *
 */

data class ListNode(
    var value: Int = 0,
    var next: ListNode? = null
)

/**
 * 第一种：没有考虑链表长度，存在溢出情况
 * @param l1 链表1
 * @param l2 链表2
 */
fun addTwoNumbers1(l1: ListNode?, l2: ListNode?): ListNode {
    println(l1)
    println(l2)

    println("---------> start <---------")

    val list1 = arrayListOf<Int>()
    val list2 = arrayListOf<Int>()

    flatNodeValue(l1, list1)
    flatNodeValue(l2, list2)

    println(list1)
    println(list2)

    val sum1 = sumNodeValue(list1)
    val sum2 = sumNodeValue(list2)
    val sum = sum1 + sum2

    println("sum1: $sum1, sum2: $sum2, sum: $sum")

    return numberToNode(sum)
}

/**
 * 链表中的节点值展开为集合
 * @param node 链表
 * @param list 集合
 */
fun flatNodeValue(node: ListNode?, list: ArrayList<Int>): ArrayList<Int> {
    if (node == null) {
        return list
    }
    list.add(node.value)
    return flatNodeValue(node.next, list)
}

/**
 * 对链表中的数求和
 * @param list
 */
fun sumNodeValue(list: ArrayList<Int>): Int {
    var sum = 0
    list.forEachIndexed { index, value ->
        val r = 10f.pow(index.toFloat()) * value
        sum += r.toInt()
    }
    return sum
}

/**
 * 将数字转为链表
 */
fun numberToNode(number: Int): ListNode {
    val source = number.toString().reversed()
    println("source: $source")

    var firstNode: ListNode? = null
    var node: ListNode? = null

    source.forEachIndexed { _, char ->
        if (node == null) {
            node = ListNode(char.digitToInt())
            firstNode = node
        } else {
            val nextNode = ListNode(char.digitToInt())
            node?.next = nextNode
            node = nextNode
        }
    }

    println(firstNode)

    return firstNode!!
}

/**
 * 第二种：解决第一种中的溢出情况，其实就是解决大数相加问题：
 *
 * 1. 将对应位的数字逆序相加，然后存到数组中
 * 2. 检查数组中的各项如果 >=10，就将该项 /10=十位上的数，再累加到后一项。将该项对 %10=个位，重新赋值给当前项
 * 3. 最后再逆序组装获得链表
 */
fun addTwoNumbers2(l1: ListNode?, l2: ListNode?): ListNode {
    println(l1)
    println(l2)

    println("---------> start <---------")

    val list1 = arrayListOf<Int>()
    val list2 = arrayListOf<Int>()

    flatNodeValue(l1, list1)
    flatNodeValue(l2, list2)

    println(list1)
    println(list2)

    return ListNode()
}

fun main() {
    val node11 = ListNode(1)
    val node12 = ListNode(2, node11)
    val node13 = ListNode(3, node12)

    // [2, 1] + [3, 2, 1] = [5, 3, 1]
    // 12 + 123 = 135
    // ListNode(value=5, next=ListNode(value=3, next=ListNode(value=1, next=null)))
    addTwoNumbers1(node12, node13)
}

Compiled from "AddTwoNumbers.kt"
public final class com.weiliange.algorithm.AddTwoNumbersKt {
  public static final com.weiliange.algorithm.ListNode addTwoNumbers1(com.weiliange.algorithm.ListNode, com.weiliange.algorithm.ListNode);
    Code:
       0: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       3: aload_0
       4: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       7: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      10: aload_1
      11: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      14: ldc           #22                 // String ---------> start <---------
      16: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      19: swap
      20: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      23: new           #24                 // class java/util/ArrayList
      26: dup
      27: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      30: astore_2
      31: new           #24                 // class java/util/ArrayList
      34: dup
      35: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      38: astore_3
      39: aload_0
      40: aload_2
      41: invokestatic  #32                 // Method flatNodeValue:(Lcom/weiliange/algorithm/ListNode;Ljava/util/ArrayList;)Ljava/util/ArrayList;
      44: pop
      45: aload_1
      46: aload_3
      47: invokestatic  #32                 // Method flatNodeValue:(Lcom/weiliange/algorithm/ListNode;Ljava/util/ArrayList;)Ljava/util/ArrayList;
      50: pop
      51: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      54: aload_2
      55: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      58: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: aload_3
      62: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: aload_2
      66: invokestatic  #36                 // Method sumNodeValue:(Ljava/util/ArrayList;)I
      69: istore        4
      71: aload_3
      72: invokestatic  #36                 // Method sumNodeValue:(Ljava/util/ArrayList;)I
      75: istore        5
      77: iload         4
      79: iload         5
      81: iadd
      82: istore        6
      84: new           #38                 // class java/lang/StringBuilder
      87: dup
      88: invokespecial #39                 // Method java/lang/StringBuilder."<init>":()V
      91: ldc           #41                 // String sum1:
      93: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      96: iload         4
      98: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     101: ldc           #50                 // String , sum2:
     103: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     106: iload         5
     108: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     111: ldc           #52                 // String , sum:
     113: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     116: iload         6
     118: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     121: invokevirtual #56                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     124: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     127: swap
     128: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     131: iload         6
     133: invokestatic  #60                 // Method numberToNode:(I)Lcom/weiliange/algorithm/ListNode;
     136: areturn

  public static final java.util.ArrayList<java.lang.Integer> flatNodeValue(com.weiliange.algorithm.ListNode, java.util.ArrayList<java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #73                 // String list
       3: invokestatic  #79                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ifnonnull     12
      10: aload_1
      11: areturn
      12: aload_1
      13: aload_0
      14: invokevirtual #85                 // Method com/weiliange/algorithm/ListNode.getValue:()I
      17: invokestatic  #91                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: invokevirtual #95                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      23: pop
      24: aload_0
      25: invokevirtual #99                 // Method com/weiliange/algorithm/ListNode.getNext:()Lcom/weiliange/algorithm/ListNode;
      28: aload_1
      29: invokestatic  #32                 // Method flatNodeValue:(Lcom/weiliange/algorithm/ListNode;Ljava/util/ArrayList;)Ljava/util/ArrayList;
      32: areturn

  public static final int sumNodeValue(java.util.ArrayList<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #73                 // String list
       3: invokestatic  #79                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: aload_0
       9: checkcast     #103                // class java/lang/Iterable
      12: astore_2
      13: iconst_0
      14: istore_3
      15: iconst_0
      16: istore        4
      18: aload_2
      19: invokeinterface #107,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      24: astore        5
      26: aload         5
      28: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          105
      36: aload         5
      38: invokeinterface #117,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: astore        6
      45: iload         4
      47: iinc          4, 1
      50: istore        7
      52: iload         7
      54: ifge          60
      57: invokestatic  #122                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      60: iload         7
      62: aload         6
      64: checkcast     #124                // class java/lang/Number
      67: invokevirtual #127                // Method java/lang/Number.intValue:()I
      70: istore        8
      72: istore        9
      74: iconst_0
      75: istore        10
      77: ldc           #128                // float 10.0f
      79: f2d
      80: iload         9
      82: i2f
      83: f2d
      84: invokestatic  #134                // Method java/lang/Math.pow:(DD)D
      87: d2f
      88: iload         8
      90: i2f
      91: fmul
      92: fstore        11
      94: iload_1
      95: fload         11
      97: f2i
      98: iadd
      99: istore_1
     100: nop
     101: nop
     102: goto          26
     105: nop
     106: iload_1
     107: ireturn

  public static final com.weiliange.algorithm.ListNode numberToNode(int);
    Code:
       0: iload_0
       1: invokestatic  #150                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
       4: checkcast     #152                // class java/lang/CharSequence
       7: invokestatic  #158                // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      10: invokevirtual #159                // Method java/lang/Object.toString:()Ljava/lang/String;
      13: astore_1
      14: new           #38                 // class java/lang/StringBuilder
      17: dup
      18: invokespecial #39                 // Method java/lang/StringBuilder."<init>":()V
      21: ldc           #161                // String source:
      23: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      26: aload_1
      27: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      30: invokevirtual #56                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      33: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: aconst_null
      41: astore_2
      42: aconst_null
      43: astore_3
      44: aload_1
      45: checkcast     #152                // class java/lang/CharSequence
      48: astore        4
      50: iconst_0
      51: istore        5
      53: iconst_0
      54: istore        6
      56: iconst_0
      57: istore        7
      59: iload         7
      61: aload         4
      63: invokeinterface #164,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      68: if_icmpge     151
      71: aload         4
      73: iload         7
      75: invokeinterface #168,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      80: istore        8
      82: iinc          6, 1
      85: iload         8
      87: istore        9
      89: iconst_0
      90: istore        10
      92: aload_3
      93: ifnonnull     117
      96: new           #81                 // class com/weiliange/algorithm/ListNode
      99: dup
     100: iload         9
     102: invokestatic  #174                // Method kotlin/text/CharsKt.digitToInt:(C)I
     105: aconst_null
     106: iconst_2
     107: aconst_null
     108: invokespecial #177                // Method com/weiliange/algorithm/ListNode."<init>":(ILcom/weiliange/algorithm/ListNode;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     111: astore_3
     112: aload_3
     113: astore_2
     114: goto          143
     117: new           #81                 // class com/weiliange/algorithm/ListNode
     120: dup
     121: iload         9
     123: invokestatic  #174                // Method kotlin/text/CharsKt.digitToInt:(C)I
     126: aconst_null
     127: iconst_2
     128: aconst_null
     129: invokespecial #177                // Method com/weiliange/algorithm/ListNode."<init>":(ILcom/weiliange/algorithm/ListNode;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     132: astore        11
     134: aload_3
     135: aload         11
     137: invokevirtual #181                // Method com/weiliange/algorithm/ListNode.setNext:(Lcom/weiliange/algorithm/ListNode;)V
     140: aload         11
     142: astore_3
     143: nop
     144: nop
     145: iinc          7, 1
     148: goto          59
     151: nop
     152: aload_2
     153: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     156: swap
     157: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     160: aload_2
     161: dup
     162: invokestatic  #184                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     165: areturn

  public static final com.weiliange.algorithm.ListNode addTwoNumbers2(com.weiliange.algorithm.ListNode, com.weiliange.algorithm.ListNode);
    Code:
       0: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       3: aload_0
       4: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       7: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      10: aload_1
      11: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      14: ldc           #22                 // String ---------> start <---------
      16: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      19: swap
      20: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      23: new           #24                 // class java/util/ArrayList
      26: dup
      27: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      30: astore_2
      31: new           #24                 // class java/util/ArrayList
      34: dup
      35: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      38: astore_3
      39: aload_0
      40: aload_2
      41: invokestatic  #32                 // Method flatNodeValue:(Lcom/weiliange/algorithm/ListNode;Ljava/util/ArrayList;)Ljava/util/ArrayList;
      44: pop
      45: aload_1
      46: aload_3
      47: invokestatic  #32                 // Method flatNodeValue:(Lcom/weiliange/algorithm/ListNode;Ljava/util/ArrayList;)Ljava/util/ArrayList;
      50: pop
      51: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      54: aload_2
      55: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      58: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: aload_3
      62: invokevirtual #20                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      65: new           #81                 // class com/weiliange/algorithm/ListNode
      68: dup
      69: iconst_0
      70: aconst_null
      71: iconst_3
      72: aconst_null
      73: invokespecial #177                // Method com/weiliange/algorithm/ListNode."<init>":(ILcom/weiliange/algorithm/ListNode;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      76: areturn

  public static final void main();
    Code:
       0: new           #81                 // class com/weiliange/algorithm/ListNode
       3: dup
       4: iconst_1
       5: aconst_null
       6: iconst_2
       7: aconst_null
       8: invokespecial #177                // Method com/weiliange/algorithm/ListNode."<init>":(ILcom/weiliange/algorithm/ListNode;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      11: astore_0
      12: new           #81                 // class com/weiliange/algorithm/ListNode
      15: dup
      16: iconst_2
      17: aload_0
      18: invokespecial #198                // Method com/weiliange/algorithm/ListNode."<init>":(ILcom/weiliange/algorithm/ListNode;)V
      21: astore_1
      22: new           #81                 // class com/weiliange/algorithm/ListNode
      25: dup
      26: iconst_3
      27: aload_1
      28: invokespecial #198                // Method com/weiliange/algorithm/ListNode."<init>":(ILcom/weiliange/algorithm/ListNode;)V
      31: astore_2
      32: aload_1
      33: aload_2
      34: invokestatic  #200                // Method addTwoNumbers1:(Lcom/weiliange/algorithm/ListNode;Lcom/weiliange/algorithm/ListNode;)Lcom/weiliange/algorithm/ListNode;
      37: pop
      38: return

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