import java.io.File
import java.lang.IllegalArgumentException

data class Range(val sourceStart: Long, val destinationStart: Long, val rangeLength: Long) {
  val sources = LongRange(sourceStart, sourceStart + rangeLength - 1)
  override fun toString(): String {
    return "$sources -> ${LongRange(destinationStart, destinationStart + rangeLength - 1)}"
  }

  fun mapId(id: Long) = destinationStart + id - sourceStart

  fun invert() = Range(destinationStart, sourceStart, rangeLength)
}

class Mapping(val name: String, ranges: Set<Range>) {
  val sortedRanges = ranges.sortedBy { it.sources.start }

  fun map(sourceId: Long): Long {
    for (range in sortedRanges) {
      if (sourceId < range.sources.start) {
        return sourceId
      } else if (sourceId in range.sources) {
        return range.mapId(sourceId)
      }
    }
    return sourceId
  }

  override fun toString(): String {
    return "Mapping:\n" + sortedRanges.joinToString(separator = "\n") { "  $it" }
  }
}

fun main() {
  val lines = File("inputs/soil.txt").readLines()

  val rawSeeds = Regex("\\d+").findAll(lines[0].split(":")[1]).map { it.value.toLong() }
  val mappings = lines.parseMappings()

  // println(calculateMinLocationSimpleSeeds(rawSeeds, mappings))

  println(calculateMinLocationSeedRanges(rawSeeds, mappings))
}

fun calculateMinLocationSeedRanges(rawSeeds: Sequence<Long>, forwardMappings: List<Mapping>): Long {
  val seedRanges = rawSeeds
    .chunked(2)
    .map { pair -> LongRange(start = pair[0], endInclusive = pair[0] + pair[1] - 1) }
    .sortedBy { range -> range.start }
    .toList()

  val reverseMappings = forwardMappings.map { mapping ->
    Mapping("~${mapping.name}", mapping.sortedRanges.map { it.invert() }.toSet())
  }.reversed()

  val locations2Humidity = reverseMappings.first()

  locations2Humidity.sortedRanges.forEach { range ->
    range.sources.forEach { location ->
      val seed = reverseMappings.fold(location)
      seedRanges.forEach { seedRange ->
        if (seed in seedRange) {
          return location
        }
      }
    }
  }
  throw IllegalArgumentException()
}

private fun calculateMinLocationSimpleSeeds(
  rawSeeds: Sequence<Long>,
  mappings: List<Mapping>,
): Long = rawSeeds.map { value ->
  mappings.fold(value)
}.min()

private fun List<Mapping>.fold(value: Long) =
  this.fold(value) { acc, mapping ->
    mapping.map(acc)
  }

private fun List<String>.parseMappings(): List<Mapping> {
  val seed2Soil = parseMapping("seed2Soil", startInclusive = 3, endExclusive = 32)
  val soil2Fertilizer = parseMapping("soil2Fertilizer", startInclusive = 34, endExclusive = 53)
  val fertilizer2Water = parseMapping("fertilizer2Water", startInclusive = 55, endExclusive = 97)
  val water2Light = parseMapping("water2Light", startInclusive = 99, endExclusive = 117)
  val light2Temperature =
    parseMapping("light2Temperature", startInclusive = 119, endExclusive = 132)
  val temperature2Humidity =
    parseMapping("temperature2Humidity", startInclusive = 135, endExclusive = 144)
  val humidity2Location =
    parseMapping("humidity2Location", startInclusive = 146, endExclusive = 190)

  return listOf(
    seed2Soil,
    soil2Fertilizer,
    fertilizer2Water,
    water2Light,
    light2Temperature,
    temperature2Humidity,
    humidity2Location
  )
}

private fun List<String>.parseMapping(
  name: String,
  startInclusive: Int,
  endExclusive: Int,
): Mapping =
  Mapping(name, subList(startInclusive, endExclusive).map { line ->
    val numbers = Regex("\\d+").findAll(line).map { it.value.toLong() }.toList()
    Range(sourceStart = numbers[1], destinationStart = numbers[0], rangeLength = numbers[2])
  }.toSet())

Compiled from "Soil.kt"
public final class SoilKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String inputs/soil.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: new           #22                 // class kotlin/text/Regex
      19: dup
      20: ldc           #24                 // String \\d+
      22: invokespecial #25                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      25: aload_0
      26: iconst_0
      27: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      32: checkcast     #33                 // class java/lang/CharSequence
      35: iconst_1
      36: anewarray     #35                 // class java/lang/String
      39: astore_2
      40: aload_2
      41: iconst_0
      42: ldc           #37                 // String :
      44: aastore
      45: aload_2
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #43                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: iconst_1
      55: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #33                 // class java/lang/CharSequence
      63: iconst_0
      64: iconst_2
      65: aconst_null
      66: invokestatic  #47                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      69: invokedynamic #67,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      74: invokestatic  #73                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      77: astore_1
      78: aload_0
      79: invokestatic  #77                 // Method parseMappings:(Ljava/util/List;)Ljava/util/List;
      82: astore_2
      83: aload_1
      84: aload_2
      85: invokestatic  #81                 // Method calculateMinLocationSeedRanges:(Lkotlin/sequences/Sequence;Ljava/util/List;)J
      88: lstore_3
      89: getstatic     #87                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: lload_3
      93: invokevirtual #93                 // Method java/io/PrintStream.println:(J)V
      96: return

  public static final long calculateMinLocationSeedRanges(kotlin.sequences.Sequence<java.lang.Long>, java.util.List<Mapping>);
    Code:
       0: aload_0
       1: ldc           #101                // String rawSeeds
       3: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #109                // String forwardMappings
       9: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_2
      14: invokestatic  #113                // Method kotlin/sequences/SequencesKt.chunked:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
      17: invokedynamic #120,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      22: invokestatic  #73                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      25: astore_3
      26: nop
      27: iconst_0
      28: istore        4
      30: aload_3
      31: new           #122                // class SoilKt$calculateMinLocationSeedRanges$$inlined$sortedBy$1
      34: dup
      35: invokespecial #124                // Method SoilKt$calculateMinLocationSeedRanges$$inlined$sortedBy$1."<init>":()V
      38: checkcast     #126                // class java/util/Comparator
      41: invokestatic  #130                // Method kotlin/sequences/SequencesKt.sortedWith:(Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Lkotlin/sequences/Sequence;
      44: invokestatic  #134                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      47: astore_2
      48: aload_1
      49: checkcast     #136                // class java/lang/Iterable
      52: astore        4
      54: iconst_0
      55: istore        5
      57: aload         4
      59: astore        6
      61: new           #138                // class java/util/ArrayList
      64: dup
      65: aload         4
      67: bipush        10
      69: invokestatic  #144                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      72: invokespecial #147                // Method java/util/ArrayList."<init>":(I)V
      75: checkcast     #149                // class java/util/Collection
      78: astore        7
      80: iconst_0
      81: istore        8
      83: aload         6
      85: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      90: astore        9
      92: aload         9
      94: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      99: ifeq          290
     102: aload         9
     104: invokeinterface #163,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     109: astore        10
     111: aload         7
     113: aload         10
     115: checkcast     #165                // class Mapping
     118: astore        11
     120: astore        29
     122: iconst_0
     123: istore        12
     125: new           #167                // class java/lang/StringBuilder
     128: dup
     129: invokespecial #168                // Method java/lang/StringBuilder."<init>":()V
     132: bipush        126
     134: invokevirtual #172                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     137: aload         11
     139: invokevirtual #176                // Method Mapping.getName:()Ljava/lang/String;
     142: invokevirtual #179                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     145: invokevirtual #182                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     148: aload         11
     150: invokevirtual #186                // Method Mapping.getSortedRanges:()Ljava/util/List;
     153: checkcast     #136                // class java/lang/Iterable
     156: astore        13
     158: astore        14
     160: iconst_0
     161: istore        18
     163: aload         13
     165: astore        19
     167: new           #138                // class java/util/ArrayList
     170: dup
     171: aload         13
     173: bipush        10
     175: invokestatic  #144                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     178: invokespecial #147                // Method java/util/ArrayList."<init>":(I)V
     181: checkcast     #149                // class java/util/Collection
     184: astore        20
     186: iconst_0
     187: istore        21
     189: aload         19
     191: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     196: astore        22
     198: aload         22
     200: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     205: ifeq          248
     208: aload         22
     210: invokeinterface #163,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     215: astore        23
     217: aload         20
     219: aload         23
     221: checkcast     #188                // class Range
     224: astore        24
     226: astore        25
     228: iconst_0
     229: istore        26
     231: aload         24
     233: invokevirtual #192                // Method Range.invert:()LRange;
     236: aload         25
     238: swap
     239: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     244: pop
     245: goto          198
     248: aload         20
     250: checkcast     #27                 // class java/util/List
     253: nop
     254: aload         14
     256: swap
     257: checkcast     #136                // class java/lang/Iterable
     260: invokestatic  #200                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     263: astore        30
     265: astore        31
     267: new           #165                // class Mapping
     270: dup
     271: aload         31
     273: aload         30
     275: invokespecial #203                // Method Mapping."<init>":(Ljava/lang/String;Ljava/util/Set;)V
     278: aload         29
     280: swap
     281: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     286: pop
     287: goto          92
     290: aload         7
     292: checkcast     #27                 // class java/util/List
     295: nop
     296: checkcast     #136                // class java/lang/Iterable
     299: invokestatic  #207                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     302: astore_3
     303: aload_3
     304: invokestatic  #211                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     307: checkcast     #165                // class Mapping
     310: astore        4
     312: aload         4
     314: invokevirtual #186                // Method Mapping.getSortedRanges:()Ljava/util/List;
     317: checkcast     #136                // class java/lang/Iterable
     320: astore        5
     322: iconst_0
     323: istore        6
     325: aload         5
     327: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     332: astore        7
     334: aload         7
     336: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     341: ifeq          525
     344: aload         7
     346: invokeinterface #163,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     351: astore        8
     353: aload         8
     355: checkcast     #188                // class Range
     358: astore        9
     360: iconst_0
     361: istore        10
     363: aload         9
     365: invokevirtual #215                // Method Range.getSources:()Lkotlin/ranges/LongRange;
     368: checkcast     #136                // class java/lang/Iterable
     371: astore        11
     373: iconst_0
     374: istore        12
     376: aload         11
     378: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     383: astore        13
     385: aload         13
     387: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     392: ifeq          519
     395: aload         13
     397: checkcast     #217                // class kotlin/collections/LongIterator
     400: invokevirtual #221                // Method kotlin/collections/LongIterator.nextLong:()J
     403: lstore        14
     405: lload         14
     407: lstore        16
     409: iconst_0
     410: istore        18
     412: aload_3
     413: lload         16
     415: invokestatic  #225                // Method fold:(Ljava/util/List;J)J
     418: lstore        19
     420: aload_2
     421: checkcast     #136                // class java/lang/Iterable
     424: astore        21
     426: iconst_0
     427: istore        22
     429: aload         21
     431: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     436: astore        23
     438: aload         23
     440: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     445: ifeq          513
     448: aload         23
     450: invokeinterface #163,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     455: astore        24
     457: aload         24
     459: checkcast     #227                // class kotlin/ranges/LongRange
     462: astore        25
     464: iconst_0
     465: istore        26
     467: aload         25
     469: invokevirtual #230                // Method kotlin/ranges/LongRange.getFirst:()J
     472: lstore        27
     474: lload         19
     476: aload         25
     478: invokevirtual #233                // Method kotlin/ranges/LongRange.getLast:()J
     481: lcmp
     482: ifgt          501
     485: lload         27
     487: lload         19
     489: lcmp
     490: ifgt          497
     493: iconst_1
     494: goto          502
     497: iconst_0
     498: goto          502
     501: iconst_0
     502: ifeq          508
     505: lload         16
     507: lreturn
     508: nop
     509: nop
     510: goto          438
     513: nop
     514: nop
     515: nop
     516: goto          385
     519: nop
     520: nop
     521: nop
     522: goto          334
     525: nop
     526: new           #235                // class java/lang/IllegalArgumentException
     529: dup
     530: invokespecial #236                // Method java/lang/IllegalArgumentException."<init>":()V
     533: athrow

  private static final long calculateMinLocationSimpleSeeds(kotlin.sequences.Sequence<java.lang.Long>, java.util.List<Mapping>);
    Code:
       0: aload_0
       1: aload_1
       2: invokedynamic #281,  0            // InvokeDynamic #2:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
       7: invokestatic  #73                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      10: invokestatic  #285                // Method kotlin/sequences/SequencesKt.minOrThrow:(Lkotlin/sequences/Sequence;)Ljava/lang/Comparable;
      13: checkcast     #287                // class java/lang/Number
      16: invokevirtual #290                // Method java/lang/Number.longValue:()J
      19: lreturn

  private static final long fold(java.util.List<Mapping>, long);
    Code:
       0: aload_0
       1: checkcast     #136                // class java/lang/Iterable
       4: astore_3
       5: lload_1
       6: lstore        4
       8: iconst_0
       9: istore        6
      11: lload         4
      13: lstore        7
      15: aload_3
      16: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      21: astore        9
      23: aload         9
      25: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          68
      33: aload         9
      35: invokeinterface #163,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: astore        10
      42: lload         7
      44: aload         10
      46: checkcast     #165                // class Mapping
      49: astore        11
      51: lstore        12
      53: iconst_0
      54: istore        14
      56: aload         11
      58: lload         12
      60: invokevirtual #294                // Method Mapping.map:(J)J
      63: lstore        7
      65: goto          23
      68: lload         7
      70: lreturn

  private static final java.util.List<Mapping> parseMappings(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc_w         #305                // String seed2Soil
       4: iconst_3
       5: bipush        32
       7: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      10: astore_1
      11: aload_0
      12: ldc_w         #311                // String soil2Fertilizer
      15: bipush        34
      17: bipush        53
      19: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      22: astore_2
      23: aload_0
      24: ldc_w         #313                // String fertilizer2Water
      27: bipush        55
      29: bipush        97
      31: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      34: astore_3
      35: aload_0
      36: ldc_w         #315                // String water2Light
      39: bipush        99
      41: bipush        117
      43: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      46: astore        4
      48: aload_0
      49: ldc_w         #317                // String light2Temperature
      52: bipush        119
      54: sipush        132
      57: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      60: astore        5
      62: aload_0
      63: ldc_w         #319                // String temperature2Humidity
      66: sipush        135
      69: sipush        144
      72: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      75: astore        6
      77: aload_0
      78: ldc_w         #321                // String humidity2Location
      81: sipush        146
      84: sipush        190
      87: invokestatic  #309                // Method parseMapping:(Ljava/util/List;Ljava/lang/String;II)LMapping;
      90: astore        7
      92: bipush        7
      94: anewarray     #165                // class Mapping
      97: astore        8
      99: aload         8
     101: iconst_0
     102: aload_1
     103: aastore
     104: aload         8
     106: iconst_1
     107: aload_2
     108: aastore
     109: aload         8
     111: iconst_2
     112: aload_3
     113: aastore
     114: aload         8
     116: iconst_3
     117: aload         4
     119: aastore
     120: aload         8
     122: iconst_4
     123: aload         5
     125: aastore
     126: aload         8
     128: iconst_5
     129: aload         6
     131: aastore
     132: aload         8
     134: bipush        6
     136: aload         7
     138: aastore
     139: aload         8
     141: invokestatic  #325                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     144: areturn

  private static final Mapping parseMapping(java.util.List<java.lang.String>, java.lang.String, int, int);
    Code:
       0: aload_1
       1: aload_0
       2: iload_2
       3: iload_3
       4: invokeinterface #331,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
       9: checkcast     #136                // class java/lang/Iterable
      12: astore        4
      14: astore        14
      16: iconst_0
      17: istore        5
      19: aload         4
      21: astore        6
      23: new           #138                // class java/util/ArrayList
      26: dup
      27: aload         4
      29: bipush        10
      31: invokestatic  #144                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      34: invokespecial #147                // Method java/util/ArrayList."<init>":(I)V
      37: checkcast     #149                // class java/util/Collection
      40: astore        7
      42: iconst_0
      43: istore        8
      45: aload         6
      47: invokeinterface #153,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        9
      54: aload         9
      56: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          181
      64: aload         9
      66: invokeinterface #163,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        10
      73: aload         7
      75: aload         10
      77: checkcast     #35                 // class java/lang/String
      80: astore        11
      82: astore        15
      84: iconst_0
      85: istore        12
      87: new           #22                 // class kotlin/text/Regex
      90: dup
      91: ldc           #24                 // String \\d+
      93: invokespecial #25                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      96: aload         11
      98: checkcast     #33                 // class java/lang/CharSequence
     101: iconst_0
     102: iconst_2
     103: aconst_null
     104: invokestatic  #47                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
     107: invokedynamic #336,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function1;
     112: invokestatic  #73                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     115: invokestatic  #134                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     118: astore        13
     120: new           #188                // class Range
     123: dup
     124: aload         13
     126: iconst_1
     127: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     132: checkcast     #287                // class java/lang/Number
     135: invokevirtual #290                // Method java/lang/Number.longValue:()J
     138: aload         13
     140: iconst_0
     141: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: checkcast     #287                // class java/lang/Number
     149: invokevirtual #290                // Method java/lang/Number.longValue:()J
     152: aload         13
     154: iconst_2
     155: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     160: checkcast     #287                // class java/lang/Number
     163: invokevirtual #290                // Method java/lang/Number.longValue:()J
     166: invokespecial #339                // Method Range."<init>":(JJJ)V
     169: aload         15
     171: swap
     172: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     177: pop
     178: goto          54
     181: aload         7
     183: checkcast     #27                 // class java/util/List
     186: nop
     187: aload         14
     189: swap
     190: checkcast     #136                // class java/lang/Iterable
     193: invokestatic  #200                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     196: astore        16
     198: astore        17
     200: new           #165                // class Mapping
     203: dup
     204: aload         17
     206: aload         16
     208: invokespecial #203                // Method Mapping."<init>":(Ljava/lang/String;Ljava/util/Set;)V
     211: areturn

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

  private static final long main$lambda$0(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #353                // String it
       4: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #358,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      13: invokestatic  #364                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      16: lreturn

  private static final kotlin.ranges.LongRange calculateMinLocationSeedRanges$lambda$1(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #367                // String pair
       4: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #227                // class kotlin/ranges/LongRange
      10: dup
      11: aload_0
      12: iconst_0
      13: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      18: checkcast     #287                // class java/lang/Number
      21: invokevirtual #290                // Method java/lang/Number.longValue:()J
      24: aload_0
      25: iconst_0
      26: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      31: checkcast     #287                // class java/lang/Number
      34: invokevirtual #290                // Method java/lang/Number.longValue:()J
      37: aload_0
      38: iconst_1
      39: invokeinterface #31,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      44: checkcast     #287                // class java/lang/Number
      47: invokevirtual #290                // Method java/lang/Number.longValue:()J
      50: ladd
      51: lconst_1
      52: lsub
      53: invokespecial #370                // Method kotlin/ranges/LongRange."<init>":(JJ)V
      56: areturn

  private static final long calculateMinLocationSimpleSeeds$lambda$8(java.util.List, long);
    Code:
       0: aload_0
       1: lload_1
       2: invokestatic  #225                // Method fold:(Ljava/util/List;J)J
       5: lreturn

  private static final long parseMapping$lambda$11$lambda$10(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #353                // String it
       4: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #358,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      13: invokestatic  #364                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      16: lreturn
}

Compiled from "Comparisons.kt"
public final class SoilKt$calculateMinLocationSeedRanges$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public SoilKt$calculateMinLocationSeedRanges$$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/LongRange
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/ranges/LongRange.getStart:()Ljava/lang/Long;
      12: checkcast     #29                 // class java/lang/Comparable
      15: aload_2
      16: checkcast     #23                 // class kotlin/ranges/LongRange
      19: astore_3
      20: astore        5
      22: iconst_0
      23: istore        4
      25: aload_3
      26: invokevirtual #27                 // Method kotlin/ranges/LongRange.getStart:()Ljava/lang/Long;
      29: aload         5
      31: swap
      32: checkcast     #29                 // class java/lang/Comparable
      35: invokestatic  #35                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      38: ireturn
}


import java.io.File

fun main() {
  // countPartNumbers()
  countGearRatios()
}

private data class PartNumber(val value: Int, val location: IntRange) {
  fun isAdjacentTo(i: Int) = i in (location.first-1)..(location.last+1)
}

private fun countGearRatios() {
  var line1: Set<PartNumber>
  var line2 = setOf<PartNumber>()
  var line3 = setOf<PartNumber>()
  var previousLine = ""
  val allRatios = File("inputs/parts.txt").readLines().map { line ->
    line1 = line2
    line2 = line3
    line3 = Regex("\\d+").findAll(line).map { PartNumber(it.value.toInt(), it.range) }.toSet()

    val ratioSum = scanRatios(previousLine, line1 + line2 + line3)

    previousLine = line
    ratioSum
  }.sum()

  println(allRatios + scanRatios(previousLine, line2 + line3))
}

private fun scanRatios(
  previousLine: String,
  partNumbers1: Set<PartNumber>,
): Int {
  val ratioSum = previousLine.mapIndexedNotNull { ix, char ->
    if (char != '*') {
      null
    } else {
      val partNumbers = partNumbers1.filter { it.isAdjacentTo(ix) }
      if (partNumbers.size == 2) {
        partNumbers[0].value * partNumbers[1].value
      } else {
        null
      }
    }
  }.sum()
  return ratioSum
}

private fun countPartNumbers() {
  var line1: Set<Int>
  var line2 = setOf<Int>()
  var line3 = setOf<Int>()
  var previousLine = ""
  val allNumbers = File("inputs/parts.txt").readLines().map { line ->
    line1 = line2
    line2 = line3
    line3 =
      line.mapIndexedNotNull { ix, char -> if (char != '.' && char.isNotANumber()) ix else null }
        .toSet()
    val line2PartNumberSum = scanPartNumbers(previousLine, line1 + line2 + line3)
    previousLine = line
    line2PartNumberSum
  }.sum()

  println(allNumbers + scanPartNumbers(previousLine, line2 + line3))
}

private fun scanPartNumbers(
  partNumberLine: String,
  partLocations: Set<Int>,
): Int {
  return Regex("\\d+").findAll(partNumberLine).mapNotNull {
    val number = it.value.toInt()
    for (i in (it.range.first - 1)..(it.range.last + 1)) {
      if (i in partLocations) {
        return@mapNotNull number
      }
    }
    null
  }.sum()
}

private fun Char.isNotANumber() = digitToIntOrNull() == null

Compiled from "Parts.kt"
public final class PartsKt {
  public static final void main();
    Code:
       0: invokestatic  #9                  // Method countGearRatios:()V
       3: return

  private static final void countGearRatios();
    Code:
       0: aconst_null
       1: astore_0
       2: aconst_null
       3: astore_1
       4: invokestatic  #15                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
       7: astore_1
       8: aconst_null
       9: astore_2
      10: invokestatic  #15                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      13: astore_2
      14: aconst_null
      15: astore_3
      16: ldc           #17                 // String
      18: astore_3
      19: new           #19                 // class java/io/File
      22: dup
      23: ldc           #21                 // String inputs/parts.txt
      25: invokespecial #25                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      28: aconst_null
      29: iconst_1
      30: aconst_null
      31: invokestatic  #31                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      34: checkcast     #33                 // class java/lang/Iterable
      37: astore        5
      39: iconst_0
      40: istore        6
      42: aload         5
      44: astore        7
      46: new           #35                 // class java/util/ArrayList
      49: dup
      50: aload         5
      52: bipush        10
      54: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      57: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
      60: checkcast     #46                 // class java/util/Collection
      63: astore        8
      65: iconst_0
      66: istore        9
      68: aload         7
      70: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      75: astore        10
      77: aload         10
      79: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      84: ifeq          187
      87: aload         10
      89: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      94: astore        11
      96: aload         8
      98: aload         11
     100: checkcast     #62                 // class java/lang/String
     103: astore        12
     105: astore        15
     107: iconst_0
     108: istore        13
     110: aload_1
     111: astore_0
     112: aload_2
     113: astore_1
     114: new           #64                 // class kotlin/text/Regex
     117: dup
     118: ldc           #66                 // String \\d+
     120: invokespecial #67                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     123: aload         12
     125: checkcast     #69                 // class java/lang/CharSequence
     128: iconst_0
     129: iconst_2
     130: aconst_null
     131: invokestatic  #73                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
     134: invokedynamic #92,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     139: invokestatic  #98                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     142: invokestatic  #102                // Method kotlin/sequences/SequencesKt.toSet:(Lkotlin/sequences/Sequence;)Ljava/util/Set;
     145: astore_2
     146: aload_3
     147: aload_0
     148: aload_1
     149: checkcast     #33                 // class java/lang/Iterable
     152: invokestatic  #106                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     155: aload_2
     156: checkcast     #33                 // class java/lang/Iterable
     159: invokestatic  #106                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     162: invokestatic  #110                // Method scanRatios:(Ljava/lang/String;Ljava/util/Set;)I
     165: istore        14
     167: aload         12
     169: astore_3
     170: iload         14
     172: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     175: aload         15
     177: swap
     178: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     183: pop
     184: goto          77
     187: aload         8
     189: checkcast     #122                // class java/util/List
     192: nop
     193: checkcast     #33                 // class java/lang/Iterable
     196: invokestatic  #126                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     199: istore        4
     201: iload         4
     203: aload_3
     204: aload_1
     205: aload_2
     206: checkcast     #33                 // class java/lang/Iterable
     209: invokestatic  #106                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     212: invokestatic  #110                // Method scanRatios:(Ljava/lang/String;Ljava/util/Set;)I
     215: iadd
     216: istore        5
     218: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
     221: iload         5
     223: invokevirtual #137                // Method java/io/PrintStream.println:(I)V
     226: return

  private static final int scanRatios(java.lang.String, java.util.Set<PartNumber>);
    Code:
       0: aload_0
       1: checkcast     #69                 // class java/lang/CharSequence
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #35                 // class java/util/ArrayList
      14: dup
      15: invokespecial #161                // Method java/util/ArrayList."<init>":()V
      18: checkcast     #46                 // class java/util/Collection
      21: astore        6
      23: iconst_0
      24: istore        7
      26: aload         5
      28: astore        8
      30: iconst_0
      31: istore        9
      33: iconst_0
      34: istore        10
      36: iconst_0
      37: istore        11
      39: iload         11
      41: aload         8
      43: invokeinterface #165,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      48: if_icmpge     273
      51: aload         8
      53: iload         11
      55: invokeinterface #169,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      60: istore        12
      62: iload         10
      64: iinc          10, 1
      67: iload         12
      69: istore        13
      71: istore        14
      73: iconst_0
      74: istore        15
      76: iload         14
      78: iload         13
      80: istore        16
      82: istore        17
      84: iconst_0
      85: istore        18
      87: iload         16
      89: bipush        42
      91: if_icmpeq     98
      94: aconst_null
      95: goto          242
      98: aload_1
      99: checkcast     #33                 // class java/lang/Iterable
     102: astore        19
     104: iconst_0
     105: istore        20
     107: aload         19
     109: astore        21
     111: new           #35                 // class java/util/ArrayList
     114: dup
     115: invokespecial #161                // Method java/util/ArrayList."<init>":()V
     118: checkcast     #46                 // class java/util/Collection
     121: astore        22
     123: iconst_0
     124: istore        23
     126: aload         21
     128: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        24
     135: aload         24
     137: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          187
     145: aload         24
     147: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        25
     154: aload         25
     156: checkcast     #171                // class PartNumber
     159: astore        26
     161: iconst_0
     162: istore        27
     164: aload         26
     166: iload         17
     168: invokevirtual #175                // Method PartNumber.isAdjacentTo:(I)Z
     171: ifeq          135
     174: aload         22
     176: aload         25
     178: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     183: pop
     184: goto          135
     187: aload         22
     189: checkcast     #122                // class java/util/List
     192: nop
     193: astore        28
     195: aload         28
     197: invokeinterface #178,  1          // InterfaceMethod java/util/List.size:()I
     202: iconst_2
     203: if_icmpne     241
     206: aload         28
     208: iconst_0
     209: invokeinterface #182,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     214: checkcast     #171                // class PartNumber
     217: invokevirtual #185                // Method PartNumber.getValue:()I
     220: aload         28
     222: iconst_1
     223: invokeinterface #182,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     228: checkcast     #171                // class PartNumber
     231: invokevirtual #185                // Method PartNumber.getValue:()I
     234: imul
     235: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     238: goto          242
     241: aconst_null
     242: nop
     243: dup
     244: ifnull        265
     247: astore        29
     249: iconst_0
     250: istore        30
     252: aload         6
     254: aload         29
     256: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     261: pop
     262: goto          266
     265: pop
     266: nop
     267: iinc          11, 1
     270: goto          39
     273: nop
     274: aload         6
     276: checkcast     #122                // class java/util/List
     279: nop
     280: checkcast     #33                 // class java/lang/Iterable
     283: invokestatic  #126                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     286: istore_2
     287: iload_2
     288: ireturn

  private static final void countPartNumbers();
    Code:
       0: aconst_null
       1: astore_0
       2: aconst_null
       3: astore_1
       4: invokestatic  #15                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
       7: astore_1
       8: new           #217                // class kotlin/jvm/internal/Ref$ObjectRef
      11: dup
      12: invokespecial #218                // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
      15: astore_2
      16: aload_2
      17: invokestatic  #15                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      20: putfield      #221                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      23: aconst_null
      24: astore_3
      25: ldc           #17                 // String
      27: astore_3
      28: new           #19                 // class java/io/File
      31: dup
      32: ldc           #21                 // String inputs/parts.txt
      34: invokespecial #25                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      37: aconst_null
      38: iconst_1
      39: aconst_null
      40: invokestatic  #31                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      43: checkcast     #33                 // class java/lang/Iterable
      46: astore        5
      48: iconst_0
      49: istore        6
      51: aload         5
      53: astore        7
      55: new           #35                 // class java/util/ArrayList
      58: dup
      59: aload         5
      61: bipush        10
      63: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      66: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
      69: checkcast     #46                 // class java/util/Collection
      72: astore        8
      74: iconst_0
      75: istore        9
      77: aload         7
      79: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        10
      86: aload         10
      88: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifeq          339
      96: aload         10
      98: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     103: astore        11
     105: aload         8
     107: aload         11
     109: checkcast     #62                 // class java/lang/String
     112: astore        12
     114: astore        33
     116: iconst_0
     117: istore        13
     119: aload_1
     120: astore_0
     121: aload_2
     122: getfield      #221                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     125: astore_1
     126: aload_2
     127: aload         12
     129: checkcast     #69                 // class java/lang/CharSequence
     132: astore        14
     134: astore        15
     136: iconst_0
     137: istore        16
     139: aload         14
     141: astore        17
     143: new           #35                 // class java/util/ArrayList
     146: dup
     147: invokespecial #161                // Method java/util/ArrayList."<init>":()V
     150: checkcast     #46                 // class java/util/Collection
     153: astore        18
     155: iconst_0
     156: istore        19
     158: aload         17
     160: astore        20
     162: iconst_0
     163: istore        21
     165: iconst_0
     166: istore        22
     168: iconst_0
     169: istore        23
     171: iload         23
     173: aload         20
     175: invokeinterface #165,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     180: if_icmpge     273
     183: aload         20
     185: iload         23
     187: invokeinterface #169,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     192: istore        24
     194: iload         22
     196: iinc          22, 1
     199: iload         24
     201: istore        25
     203: istore        26
     205: iconst_0
     206: istore        27
     208: iload         26
     210: iload         25
     212: istore        28
     214: istore        29
     216: iconst_0
     217: istore        30
     219: iload         28
     221: bipush        46
     223: if_icmpeq     242
     226: iload         28
     228: invokestatic  #225                // Method isNotANumber:(C)Z
     231: ifeq          242
     234: iload         29
     236: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     239: goto          243
     242: aconst_null
     243: dup
     244: ifnull        265
     247: astore        31
     249: iconst_0
     250: istore        32
     252: aload         18
     254: aload         31
     256: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     261: pop
     262: goto          266
     265: pop
     266: nop
     267: iinc          23, 1
     270: goto          171
     273: nop
     274: aload         18
     276: checkcast     #122                // class java/util/List
     279: nop
     280: aload         15
     282: swap
     283: checkcast     #33                 // class java/lang/Iterable
     286: invokestatic  #228                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     289: putfield      #221                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     292: aload_3
     293: aload_0
     294: checkcast     #158                // class java/util/Set
     297: aload_1
     298: checkcast     #33                 // class java/lang/Iterable
     301: invokestatic  #106                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     304: aload_2
     305: getfield      #221                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     308: checkcast     #33                 // class java/lang/Iterable
     311: invokestatic  #106                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     314: invokestatic  #231                // Method scanPartNumbers:(Ljava/lang/String;Ljava/util/Set;)I
     317: istore        14
     319: aload         12
     321: astore_3
     322: iload         14
     324: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     327: aload         33
     329: swap
     330: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     335: pop
     336: goto          86
     339: aload         8
     341: checkcast     #122                // class java/util/List
     344: nop
     345: checkcast     #33                 // class java/lang/Iterable
     348: invokestatic  #126                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     351: istore        4
     353: iload         4
     355: aload_3
     356: aload_1
     357: checkcast     #158                // class java/util/Set
     360: aload_2
     361: getfield      #221                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     364: checkcast     #33                 // class java/lang/Iterable
     367: invokestatic  #106                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     370: invokestatic  #231                // Method scanPartNumbers:(Ljava/lang/String;Ljava/util/Set;)I
     373: iadd
     374: istore        5
     376: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
     379: iload         5
     381: invokevirtual #137                // Method java/io/PrintStream.println:(I)V
     384: return

  private static final int scanPartNumbers(java.lang.String, java.util.Set<java.lang.Integer>);
    Code:
       0: new           #64                 // class kotlin/text/Regex
       3: dup
       4: ldc           #66                 // String \\d+
       6: invokespecial #67                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: aload_0
      10: checkcast     #69                 // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #73                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      19: aload_1
      20: invokedynamic #247,  0            // InvokeDynamic #1:invoke:(Ljava/util/Set;)Lkotlin/jvm/functions/Function1;
      25: invokestatic  #250                // Method kotlin/sequences/SequencesKt.mapNotNull:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      28: invokestatic  #253                // Method kotlin/sequences/SequencesKt.sumOfInt:(Lkotlin/sequences/Sequence;)I
      31: ireturn

  private static final boolean isNotANumber(char);
    Code:
       0: iload_0
       1: invokestatic  #261                // Method kotlin/text/CharsKt.digitToIntOrNull:(C)Ljava/lang/Integer;
       4: ifnonnull     11
       7: iconst_1
       8: goto          12
      11: iconst_0
      12: ireturn

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

  private static final PartNumber countGearRatios$lambda$1$lambda$0(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #268                // String it
       4: invokestatic  #274                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #171                // class PartNumber
      10: dup
      11: aload_0
      12: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      17: invokestatic  #283                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      20: aload_0
      21: invokeinterface #287,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      26: invokespecial #290                // Method PartNumber."<init>":(ILkotlin/ranges/IntRange;)V
      29: areturn

  private static final java.lang.Integer scanPartNumbers$lambda$6(java.util.Set, kotlin.text.MatchResult);
    Code:
       0: aload_1
       1: ldc_w         #268                // String it
       4: invokestatic  #274                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      13: invokestatic  #283                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      16: istore_2
      17: aload_1
      18: invokeinterface #287,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      23: invokevirtual #296                // Method kotlin/ranges/IntRange.getFirst:()I
      26: iconst_1
      27: isub
      28: istore_3
      29: aload_1
      30: invokeinterface #287,  1          // InterfaceMethod kotlin/text/MatchResult.getRange:()Lkotlin/ranges/IntRange;
      35: invokevirtual #299                // Method kotlin/ranges/IntRange.getLast:()I
      38: iconst_1
      39: iadd
      40: istore        4
      42: iload_3
      43: iload         4
      45: if_icmpgt     78
      48: aload_0
      49: iload_3
      50: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: invokeinterface #302,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      58: ifeq          66
      61: iload_2
      62: invokestatic  #116                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: areturn
      66: iload_3
      67: iload         4
      69: if_icmpeq     78
      72: iinc          3, 1
      75: goto          48
      78: aconst_null
      79: areturn
}


import Card.Companion.toCard
import java.io.File

fun main() {

  val lines = File("aoc/inputs/hands.txt").readLines()

  println(linesToWinnings(lines))
}

internal fun linesToWinnings(lines: List<String>): Int {
  return lines
    .map { line ->
      HandWinnings(
        Hand(line.substring(0, 5).map { it.toCard() }),
        line.substring(6).toInt()
      )
    }
    .sortedByDescending(HandWinnings::hand)
    .mapIndexed { ix, handWinnings -> (ix + 1) * handWinnings.winnings }
    .sum()
}

data class HandWinnings(val hand: Hand, val winnings: Int)

enum class Card(val representation: Char) {
  Ace('A'),
  King('K'),
  Queen('Q'),
  // Jack('J'),
  Ten('T'),
  Nine('9'),
  Eight('8'),
  Seven('7'),
  Six('6'),
  Five('5'),
  Four('4'),
  Three('3'),
  Two('2'),
  Joker('J');

  companion object {
    fun Char.toCard(): Card {
      for (card in entries) {
        if (this == card.representation) {
          return card
        }
      }
      throw IllegalArgumentException("Non-card character '$this'")
    }
  }
}

enum class Type { Five, Four, FullHouse, Three, TwoPair, OnePair, High }

class Hand(private val cards: List<Card>) : Comparable<Hand> {

  private val distribution: Map<Card, Int> =
    cards.fold(mutableMapOf()) { dist, card ->
      dist[card] = dist.getOrDefault(card, 0) + 1
      dist
    }

  private val type: Type
    get() {
      return when (distribution.size) {
        1 -> Type.Five
        2 -> if (distribution.values.any { it == 4 }) Type.Four else Type.FullHouse
        3 -> if (distribution.values.any { it == 3 }) Type.Three else Type.TwoPair
        4 -> Type.OnePair
        5 -> Type.High
        else -> throw IllegalStateException("Wrong number of cards")
      }
    }

  private val complexType: Type
    get() {

      var nonJokers = 0
      val distribution = cards.fold(mutableMapOf<Card, Int>()) { dist, card ->
        if (card != Card.Joker) {
          dist[card] = dist.getOrDefault(card, 0) + 1
          nonJokers++
        }
        dist
      }
      val jokers = 5 - nonJokers

      return when (distribution.size) {
        0 -> Type.Five // All jokers
        1 -> Type.Five // Jokers become the one other card type
        2 -> if (distribution.values.any { it == nonJokers - 1 }) Type.Four else Type.FullHouse
        3 -> if (distribution.values.any { it == 3-jokers }) Type.Three else Type.TwoPair
        4 -> Type.OnePair
        5 -> Type.High
        else -> throw IllegalStateException("Wrong number of cards")
      }

    }

  override operator fun compareTo(other: Hand): Int {
    if (this.complexType != other.complexType) {
      return this.complexType.compareTo(other.complexType)
    }

    for (i in 0..4) {
      if (this.cards[i] != other.cards[i]) {
        return this.cards[i].compareTo(other.cards[i])
      }
    }
    return 0
  }
}

Compiled from "Comparisons.kt"
public final class HandsKt$linesToWinnings$$inlined$sortedByDescending$1<T> implements java.util.Comparator {
  public HandsKt$linesToWinnings$$inlined$sortedByDescending$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_2
       1: checkcast     #23                 // class HandWinnings
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method HandWinnings.getHand:()LHand;
      12: checkcast     #29                 // class java/lang/Comparable
      15: aload_1
      16: checkcast     #23                 // class HandWinnings
      19: astore_3
      20: astore        5
      22: iconst_0
      23: istore        4
      25: aload_3
      26: invokevirtual #27                 // Method HandWinnings.getHand:()LHand;
      29: aload         5
      31: swap
      32: checkcast     #29                 // class java/lang/Comparable
      35: invokestatic  #35                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      38: ireturn
}

Compiled from "Hands.kt"
public final class HandsKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String aoc/inputs/hands.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: invokestatic  #24                 // Method linesToWinnings:(Ljava/util/List;)I
      20: istore_1
      21: getstatic     #30                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: iload_1
      25: invokevirtual #36                 // Method java/io/PrintStream.println:(I)V
      28: return

  public static final int linesToWinnings(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #41                 // String lines
       3: invokestatic  #47                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #49                 // class java/lang/Iterable
      10: astore_1
      11: nop
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #51                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #57                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #59                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #61                 // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #65,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          247
      55: aload         6
      57: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #77                 // class java/lang/String
      71: astore        8
      73: astore        22
      75: iconst_0
      76: istore        9
      78: aload         8
      80: iconst_0
      81: iconst_5
      82: invokevirtual #81                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      85: dup
      86: ldc           #83                 // String substring(...)
      88: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      91: checkcast     #88                 // class java/lang/CharSequence
      94: astore        10
      96: iconst_0
      97: istore        13
      99: aload         10
     101: astore        14
     103: new           #51                 // class java/util/ArrayList
     106: dup
     107: aload         10
     109: invokeinterface #92,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     114: invokespecial #59                 // Method java/util/ArrayList."<init>":(I)V
     117: checkcast     #61                 // class java/util/Collection
     120: astore        15
     122: iconst_0
     123: istore        16
     125: iconst_0
     126: istore        17
     128: iload         17
     130: aload         14
     132: invokeinterface #92,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     137: if_icmpge     185
     140: aload         14
     142: iload         17
     144: invokeinterface #96,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     149: istore        18
     151: aload         15
     153: iload         18
     155: istore        19
     157: astore        20
     159: iconst_0
     160: istore        21
     162: getstatic     #102                // Field Card.Companion:LCard$Companion;
     165: iload         19
     167: invokevirtual #108                // Method Card$Companion.toCard:(C)LCard;
     170: aload         20
     172: swap
     173: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     178: pop
     179: iinc          17, 1
     182: goto          128
     185: aload         15
     187: checkcast     #114                // class java/util/List
     190: nop
     191: astore        23
     193: new           #116                // class Hand
     196: dup
     197: aload         23
     199: invokespecial #119                // Method Hand."<init>":(Ljava/util/List;)V
     202: nop
     203: aload         8
     205: bipush        6
     207: invokevirtual #122                // Method java/lang/String.substring:(I)Ljava/lang/String;
     210: dup
     211: ldc           #83                 // String substring(...)
     213: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     216: invokestatic  #128                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     219: istore        24
     221: astore        25
     223: new           #130                // class HandWinnings
     226: dup
     227: aload         25
     229: iload         24
     231: invokespecial #133                // Method HandWinnings."<init>":(LHand;I)V
     234: nop
     235: aload         22
     237: swap
     238: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     243: pop
     244: goto          45
     247: aload         4
     249: checkcast     #114                // class java/util/List
     252: nop
     253: checkcast     #49                 // class java/lang/Iterable
     256: astore_1
     257: nop
     258: iconst_0
     259: istore_2
     260: aload_1
     261: new           #135                // class HandsKt$linesToWinnings$$inlined$sortedByDescending$1
     264: dup
     265: invokespecial #137                // Method HandsKt$linesToWinnings$$inlined$sortedByDescending$1."<init>":()V
     268: checkcast     #139                // class java/util/Comparator
     271: invokestatic  #143                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     274: checkcast     #49                 // class java/lang/Iterable
     277: astore_1
     278: nop
     279: iconst_0
     280: istore_2
     281: aload_1
     282: astore_3
     283: new           #51                 // class java/util/ArrayList
     286: dup
     287: aload_1
     288: bipush        10
     290: invokestatic  #57                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     293: invokespecial #59                 // Method java/util/ArrayList."<init>":(I)V
     296: checkcast     #61                 // class java/util/Collection
     299: astore        4
     301: iconst_0
     302: istore        5
     304: iconst_0
     305: istore        6
     307: aload_3
     308: invokeinterface #65,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     313: astore        7
     315: aload         7
     317: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     322: ifeq          392
     325: aload         7
     327: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     332: astore        8
     334: aload         4
     336: iload         6
     338: iinc          6, 1
     341: istore        9
     343: iload         9
     345: ifge          351
     348: invokestatic  #146                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     351: iload         9
     353: aload         8
     355: checkcast     #130                // class HandWinnings
     358: astore        10
     360: istore        11
     362: astore        22
     364: iconst_0
     365: istore        12
     367: iload         11
     369: iconst_1
     370: iadd
     371: aload         10
     373: invokevirtual #149                // Method HandWinnings.getWinnings:()I
     376: imul
     377: invokestatic  #153                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     380: aload         22
     382: swap
     383: invokeinterface #112,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     388: pop
     389: goto          315
     392: aload         4
     394: checkcast     #114                // class java/util/List
     397: nop
     398: checkcast     #49                 // class java/lang/Iterable
     401: invokestatic  #157                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     404: ireturn

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


import java.io.File

fun main() {
 // problem1()
  problem2()
}

private fun problem2() {
  var powerSum = 0
  val colors = listOf("red", "green", "blue")
  File("inputs/colorGame.txt").forEachLine { line ->
    val split = line.split(":")
    val maxes = colors.associateWith { 0 }.toMutableMap()
    split[1].split(";").forEach {
      it.split(",").forEach { color ->
        for ((name, max) in maxes) {
          if (color.contains(name)) {
            val count = Regex("\\d+").find(color)?.value?.toInt() ?: 0
            if (count > max) {
              maxes[name] = count
            }
          }
        }
      }
    }
    powerSum += maxes.values.reduce { acc, value -> acc * value }
  }
  println(powerSum)
}

private fun problem1() {
  val colors = mapOf("red" to 12, "green" to 13, "blue" to 14)
  var validGamesSum = 0
  File("inputs/colorGame.txt").forEachLine { line ->
    val split = line.split(":")
    val gameId = split[0].substring(5).toInt()
    split[1].split(";").forEach {
      it.split(",").forEach { color ->
        for ((name, max) in colors) {
          if (color.contains(name)) {
            if ((Regex("\\d+").find(color)?.value?.toInt() ?: 0) > max) {
              return@forEachLine
            }
          }
        }
      }
    }
    validGamesSum += gameId
  }
  println(validGamesSum)
}

Compiled from "ColorGame.kt"
public final class ColorGameKt {
  public static final void main();
    Code:
       0: invokestatic  #9                  // Method problem2:()V
       3: return

  private static final void problem2();
    Code:
       0: new           #11                 // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #14                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_0
       8: iconst_3
       9: anewarray     #16                 // class java/lang/String
      12: astore_2
      13: aload_2
      14: iconst_0
      15: ldc           #18                 // String red
      17: aastore
      18: aload_2
      19: iconst_1
      20: ldc           #20                 // String green
      22: aastore
      23: aload_2
      24: iconst_2
      25: ldc           #22                 // String blue
      27: aastore
      28: aload_2
      29: invokestatic  #28                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      32: astore_1
      33: new           #30                 // class java/io/File
      36: dup
      37: ldc           #32                 // String inputs/colorGame.txt
      39: invokespecial #35                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      42: aconst_null
      43: aload_1
      44: aload_0
      45: invokedynamic #55,  0             // InvokeDynamic #0:invoke:(Ljava/util/List;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
      50: iconst_1
      51: aconst_null
      52: invokestatic  #61                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      55: aload_0
      56: getfield      #65                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      59: istore_2
      60: getstatic     #71                 // Field java/lang/System.out:Ljava/io/PrintStream;
      63: iload_2
      64: invokevirtual #77                 // Method java/io/PrintStream.println:(I)V
      67: return

  private static final void problem1();
    Code:
       0: iconst_3
       1: anewarray     #84                 // class kotlin/Pair
       4: astore_1
       5: aload_1
       6: iconst_0
       7: ldc           #18                 // String red
       9: bipush        12
      11: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokestatic  #96                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      17: aastore
      18: aload_1
      19: iconst_1
      20: ldc           #20                 // String green
      22: bipush        13
      24: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: invokestatic  #96                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      30: aastore
      31: aload_1
      32: iconst_2
      33: ldc           #22                 // String blue
      35: bipush        14
      37: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokestatic  #96                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      43: aastore
      44: aload_1
      45: invokestatic  #102                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      48: astore_0
      49: new           #11                 // class kotlin/jvm/internal/Ref$IntRef
      52: dup
      53: invokespecial #14                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      56: astore_1
      57: new           #30                 // class java/io/File
      60: dup
      61: ldc           #32                 // String inputs/colorGame.txt
      63: invokespecial #35                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      66: aconst_null
      67: aload_1
      68: aload_0
      69: invokedynamic #110,  0            // InvokeDynamic #1:invoke:(Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/Map;)Lkotlin/jvm/functions/Function1;
      74: iconst_1
      75: aconst_null
      76: invokestatic  #61                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      79: aload_1
      80: getfield      #65                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      83: istore_2
      84: getstatic     #71                 // Field java/lang/System.out:Ljava/io/PrintStream;
      87: iload_2
      88: invokevirtual #77                 // Method java/io/PrintStream.println:(I)V
      91: return

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

  private static final kotlin.Unit problem2$lambda$4(java.util.List, kotlin.jvm.internal.Ref$IntRef, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #119                // String line
       3: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: checkcast     #127                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #16                 // class java/lang/String
      14: astore        4
      16: aload         4
      18: iconst_0
      19: ldc           #129                // String :
      21: aastore
      22: aload         4
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: astore_3
      33: aload_0
      34: checkcast     #137                // class java/lang/Iterable
      37: astore        5
      39: iconst_0
      40: istore        6
      42: new           #139                // class java/util/LinkedHashMap
      45: dup
      46: aload         5
      48: bipush        10
      50: invokestatic  #143                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      53: invokestatic  #147                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      56: bipush        16
      58: invokestatic  #153                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      61: invokespecial #155                // Method java/util/LinkedHashMap."<init>":(I)V
      64: astore        7
      66: aload         5
      68: astore        8
      70: iconst_0
      71: istore        9
      73: aload         8
      75: invokeinterface #159,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      80: astore        10
      82: aload         10
      84: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      89: ifeq          143
      92: aload         10
      94: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      99: astore        11
     101: aload         7
     103: checkcast     #171                // class java/util/Map
     106: aload         11
     108: aload         11
     110: checkcast     #16                 // class java/lang/String
     113: astore        12
     115: astore        24
     117: astore        23
     119: iconst_0
     120: istore        13
     122: iconst_0
     123: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     126: astore        25
     128: aload         23
     130: aload         24
     132: aload         25
     134: invokeinterface #175,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     139: pop
     140: goto          82
     143: aload         7
     145: checkcast     #171                // class java/util/Map
     148: nop
     149: invokestatic  #179                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     152: astore        4
     154: aload_3
     155: iconst_1
     156: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     161: checkcast     #127                // class java/lang/CharSequence
     164: iconst_1
     165: anewarray     #16                 // class java/lang/String
     168: astore        5
     170: aload         5
     172: iconst_0
     173: ldc           #187                // String ;
     175: aastore
     176: aload         5
     178: iconst_0
     179: iconst_0
     180: bipush        6
     182: aconst_null
     183: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     186: checkcast     #137                // class java/lang/Iterable
     189: astore        5
     191: iconst_0
     192: istore        6
     194: aload         5
     196: invokeinterface #159,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     201: astore        7
     203: aload         7
     205: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     210: ifeq          470
     213: aload         7
     215: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     220: astore        8
     222: aload         8
     224: checkcast     #16                 // class java/lang/String
     227: astore        9
     229: iconst_0
     230: istore        10
     232: aload         9
     234: checkcast     #127                // class java/lang/CharSequence
     237: iconst_1
     238: anewarray     #16                 // class java/lang/String
     241: astore        11
     243: aload         11
     245: iconst_0
     246: ldc           #189                // String ,
     248: aastore
     249: aload         11
     251: iconst_0
     252: iconst_0
     253: bipush        6
     255: aconst_null
     256: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     259: checkcast     #137                // class java/lang/Iterable
     262: astore        11
     264: iconst_0
     265: istore        12
     267: aload         11
     269: invokeinterface #159,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     274: astore        13
     276: aload         13
     278: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     283: ifeq          464
     286: aload         13
     288: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     293: astore        14
     295: aload         14
     297: checkcast     #16                 // class java/lang/String
     300: astore        15
     302: iconst_0
     303: istore        16
     305: aload         4
     307: invokeinterface #193,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     312: invokeinterface #196,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     317: astore        17
     319: aload         17
     321: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     326: ifeq          459
     329: aload         17
     331: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     336: checkcast     #198                // class java/util/Map$Entry
     339: astore        18
     341: aload         18
     343: invokeinterface #201,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     348: checkcast     #16                 // class java/lang/String
     351: astore        19
     353: aload         18
     355: invokeinterface #204,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     360: checkcast     #206                // class java/lang/Number
     363: invokevirtual #210                // Method java/lang/Number.intValue:()I
     366: istore        20
     368: aload         15
     370: checkcast     #127                // class java/lang/CharSequence
     373: aload         19
     375: checkcast     #127                // class java/lang/CharSequence
     378: iconst_0
     379: iconst_2
     380: aconst_null
     381: invokestatic  #214                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
     384: ifeq          319
     387: new           #216                // class kotlin/text/Regex
     390: dup
     391: ldc           #218                // String \\d+
     393: invokespecial #219                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     396: aload         15
     398: checkcast     #127                // class java/lang/CharSequence
     401: iconst_0
     402: iconst_2
     403: aconst_null
     404: invokestatic  #223                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     407: dup
     408: ifnull        426
     411: invokeinterface #228,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     416: dup
     417: ifnull        426
     420: invokestatic  #232                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     423: goto          428
     426: pop
     427: iconst_0
     428: istore        21
     430: iload         21
     432: iload         20
     434: if_icmple     319
     437: iload         21
     439: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     442: astore        22
     444: aload         4
     446: aload         19
     448: aload         22
     450: invokeinterface #175,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     455: pop
     456: goto          319
     459: nop
     460: nop
     461: goto          276
     464: nop
     465: nop
     466: nop
     467: goto          203
     470: nop
     471: aload_1
     472: aload_1
     473: getfield      #65                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     476: aload         4
     478: invokeinterface #236,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     483: checkcast     #137                // class java/lang/Iterable
     486: astore        5
     488: istore        24
     490: astore        23
     492: iconst_0
     493: istore        6
     495: aload         5
     497: invokeinterface #159,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     502: astore        7
     504: aload         7
     506: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     511: ifne          524
     514: new           #238                // class java/lang/UnsupportedOperationException
     517: dup
     518: ldc           #240                // String Empty collection can\'t be reduced.
     520: invokespecial #241                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     523: athrow
     524: aload         7
     526: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     531: astore        8
     533: aload         7
     535: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     540: ifeq          584
     543: aload         8
     545: aload         7
     547: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     552: checkcast     #206                // class java/lang/Number
     555: invokevirtual #210                // Method java/lang/Number.intValue:()I
     558: istore        9
     560: checkcast     #206                // class java/lang/Number
     563: invokevirtual #210                // Method java/lang/Number.intValue:()I
     566: istore        10
     568: iconst_0
     569: istore        11
     571: iload         10
     573: iload         9
     575: imul
     576: invokestatic  #90                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     579: astore        8
     581: goto          533
     584: aload         8
     586: astore        25
     588: aload         23
     590: iload         24
     592: aload         25
     594: checkcast     #206                // class java/lang/Number
     597: invokevirtual #210                // Method java/lang/Number.intValue:()I
     600: iadd
     601: putfield      #65                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     604: getstatic     #247                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     607: areturn

  private static final kotlin.Unit problem1$lambda$7(kotlin.jvm.internal.Ref$IntRef, java.util.Map, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #119                // String line
       3: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: checkcast     #127                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #16                 // class java/lang/String
      14: astore        4
      16: aload         4
      18: iconst_0
      19: ldc           #129                // String :
      21: aastore
      22: aload         4
      24: iconst_0
      25: iconst_0
      26: bipush        6
      28: aconst_null
      29: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      32: astore_3
      33: nop
      34: aload_3
      35: iconst_0
      36: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      41: checkcast     #16                 // class java/lang/String
      44: iconst_5
      45: invokevirtual #285                // Method java/lang/String.substring:(I)Ljava/lang/String;
      48: dup
      49: ldc_w         #287                // String substring(...)
      52: invokestatic  #290                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      55: invokestatic  #232                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      58: istore        4
      60: aload_3
      61: iconst_1
      62: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #127                // class java/lang/CharSequence
      70: iconst_1
      71: anewarray     #16                 // class java/lang/String
      74: astore        5
      76: aload         5
      78: iconst_0
      79: ldc           #187                // String ;
      81: aastore
      82: aload         5
      84: iconst_0
      85: iconst_0
      86: bipush        6
      88: aconst_null
      89: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      92: checkcast     #137                // class java/lang/Iterable
      95: astore        5
      97: iconst_0
      98: istore        6
     100: aload         5
     102: invokeinterface #159,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     107: astore        7
     109: aload         7
     111: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     116: ifeq          353
     119: aload         7
     121: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     126: astore        8
     128: aload         8
     130: checkcast     #16                 // class java/lang/String
     133: astore        9
     135: iconst_0
     136: istore        10
     138: aload         9
     140: checkcast     #127                // class java/lang/CharSequence
     143: iconst_1
     144: anewarray     #16                 // class java/lang/String
     147: astore        11
     149: aload         11
     151: iconst_0
     152: ldc           #189                // String ,
     154: aastore
     155: aload         11
     157: iconst_0
     158: iconst_0
     159: bipush        6
     161: aconst_null
     162: invokestatic  #135                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     165: checkcast     #137                // class java/lang/Iterable
     168: astore        11
     170: iconst_0
     171: istore        12
     173: aload         11
     175: invokeinterface #159,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        13
     182: aload         13
     184: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          347
     192: aload         13
     194: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        14
     201: aload         14
     203: checkcast     #16                 // class java/lang/String
     206: astore        15
     208: iconst_0
     209: istore        16
     211: aload_1
     212: invokeinterface #193,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     217: invokeinterface #196,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     222: astore        17
     224: aload         17
     226: invokeinterface #165,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          342
     234: aload         17
     236: invokeinterface #169,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     241: checkcast     #198                // class java/util/Map$Entry
     244: astore        18
     246: aload         18
     248: invokeinterface #201,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     253: checkcast     #16                 // class java/lang/String
     256: astore        19
     258: aload         18
     260: invokeinterface #204,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     265: checkcast     #206                // class java/lang/Number
     268: invokevirtual #210                // Method java/lang/Number.intValue:()I
     271: istore        20
     273: aload         15
     275: checkcast     #127                // class java/lang/CharSequence
     278: aload         19
     280: checkcast     #127                // class java/lang/CharSequence
     283: iconst_0
     284: iconst_2
     285: aconst_null
     286: invokestatic  #214                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
     289: ifeq          224
     292: new           #216                // class kotlin/text/Regex
     295: dup
     296: ldc           #218                // String \\d+
     298: invokespecial #219                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     301: aload         15
     303: checkcast     #127                // class java/lang/CharSequence
     306: iconst_0
     307: iconst_2
     308: aconst_null
     309: invokestatic  #223                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
     312: dup
     313: ifnull        331
     316: invokeinterface #228,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
     321: dup
     322: ifnull        331
     325: invokestatic  #232                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     328: goto          333
     331: pop
     332: iconst_0
     333: iload         20
     335: if_icmple     224
     338: getstatic     #247                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     341: areturn
     342: nop
     343: nop
     344: goto          182
     347: nop
     348: nop
     349: nop
     350: goto          109
     353: nop
     354: aload_0
     355: aload_0
     356: getfield      #65                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     359: iload         4
     361: iadd
     362: putfield      #65                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     365: getstatic     #247                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     368: areturn
}