package io.steinh.aoc.day02

class CubeConundrum {

    fun sumIds(lines: List<String>, bagLimits: List<CubeCount>): Int {
        val processed = analyze(lines)

        var sum = 0
        for (game in processed) {
            var match = true

            for (entry in game.value) {
                for (limit in bagLimits) {
                    match = match && entry.any { it.color == limit.color && it.count <= limit.count }
                }
            }

            if (match) {
                print("Game ${game.key} is possible\n")
                sum += game.key
            }
        }

        return sum
    }

    fun powerOfTheFewest(lines: List<String>): Int {
        val processed = analyze(lines)

        val fewest = getFewest(processed)

        var result = 0

        for (game in fewest) {
            val value = game.value.map { it.count }.reduce { acc, i -> acc * i }

            result += value
        }

        return result
    }

    private fun getFewest(processed: Map<Int, List<List<CubeCount>>>): Map<Int, List<CubeCount>> {
        val result = mutableMapOf<Int, List<CubeCount>>()

        for (game in processed) {
            var red = 0
            var green = 0
            var blue = 0

            for (set in game.value) {
                for (entry in set) {
                    when (entry.color) {
                        "red" -> red = if (red < entry.count) entry.count else red
                        "green" -> green = if (green < entry.count) entry.count else green
                        "blue" -> blue = if (blue < entry.count) entry.count else blue
                    }

                }
            }

            result[game.key] = listOf(
                CubeCount(red, "red"),
                CubeCount(green, "green"),
                CubeCount(blue, "blue")
            )
        }

        return result
    }

    private fun analyze(lines: List<String>): Map<Int, List<List<CubeCount>>> {
        val result: MutableMap<Int, List<List<CubeCount>>> = mutableMapOf()
        for (line in lines) {
            val gameId = "Game (\\d+)".toRegex().find(line)!!.groupValues[1].toInt()

            val drawnSets = line.split(": ").last().split(";")

            val sets = buildList {
                for (set in drawnSets) {
                    add(
                        buildList {

                            var redCubes = 0
                            var greenCubes = 0
                            var blueCubes = 0
                            for (matches in "(\\d+) (red|green|blue)".toRegex().findAll(set)) {

                                val cnt = matches.groups[1]!!.value.toInt()

                                when (matches.groups[2]!!.value) {
                                    "red" -> redCubes += cnt
                                    "green" -> greenCubes += cnt
                                    "blue" -> blueCubes += cnt
                                }

                            }
                            add(CubeCount(redCubes, "red"))
                            add(CubeCount(blueCubes, "blue"))
                            add(CubeCount(greenCubes, "green"))
                        })
                }
            }

            result.put(gameId, sets)
        }

        return result
    }

}

data class CubeCount(
    val count: Int,
    val color: String,
)

fun main() {
    val input = {}.javaClass.classLoader?.getResource("day02/input.txt")?.readText()?.lines()!!

    val bagLimits = listOf(
        CubeCount(12, "red"),
        CubeCount(13, "green"),
        CubeCount(14, "blue")
    )

    val cubeConundrum = CubeConundrum()
    val result = cubeConundrum.sumIds(input, bagLimits)
    val resultPart2 = cubeConundrum.powerOfTheFewest(input)

    print("Solution for Day 2, Part  I: $result\n")
    print("Solution for Day 2, Part II: $resultPart2\n")
}

Compiled from "CubeConundrum.kt"
public final class io.steinh.aoc.day02.CubeConundrumKt {
  public static final void main();
    Code:
       0: invokedynamic #25,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function0;
       5: invokevirtual #29                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
       8: invokevirtual #35                 // Method java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader;
      11: dup
      12: ifnull        58
      15: ldc           #37                 // String day02/input.txt
      17: invokevirtual #43                 // Method java/lang/ClassLoader.getResource:(Ljava/lang/String;)Ljava/net/URL;
      20: dup
      21: ifnull        58
      24: astore        4
      26: getstatic     #49                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      29: astore        5
      31: aload         4
      33: invokestatic  #55                 // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      36: astore        6
      38: new           #57                 // class java/lang/String
      41: dup
      42: aload         6
      44: aload         5
      46: invokespecial #61                 // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      49: checkcast     #63                 // class java/lang/CharSequence
      52: invokestatic  #69                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      55: goto          60
      58: pop
      59: aconst_null
      60: dup
      61: invokestatic  #75                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      64: astore_0
      65: iconst_3
      66: anewarray     #77                 // class io/steinh/aoc/day02/CubeCount
      69: astore_2
      70: aload_2
      71: iconst_0
      72: new           #77                 // class io/steinh/aoc/day02/CubeCount
      75: dup
      76: bipush        12
      78: ldc           #79                 // String red
      80: invokespecial #82                 // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
      83: aastore
      84: aload_2
      85: iconst_1
      86: new           #77                 // class io/steinh/aoc/day02/CubeCount
      89: dup
      90: bipush        13
      92: ldc           #84                 // String green
      94: invokespecial #82                 // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
      97: aastore
      98: aload_2
      99: iconst_2
     100: new           #77                 // class io/steinh/aoc/day02/CubeCount
     103: dup
     104: bipush        14
     106: ldc           #86                 // String blue
     108: invokespecial #82                 // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     111: aastore
     112: aload_2
     113: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     116: astore_1
     117: new           #94                 // class io/steinh/aoc/day02/CubeConundrum
     120: dup
     121: invokespecial #96                 // Method io/steinh/aoc/day02/CubeConundrum."<init>":()V
     124: astore_2
     125: aload_2
     126: aload_0
     127: aload_1
     128: invokevirtual #100                // Method io/steinh/aoc/day02/CubeConundrum.sumIds:(Ljava/util/List;Ljava/util/List;)I
     131: istore_3
     132: aload_2
     133: aload_0
     134: invokevirtual #104                // Method io/steinh/aoc/day02/CubeConundrum.powerOfTheFewest:(Ljava/util/List;)I
     137: istore        4
     139: new           #106                // class java/lang/StringBuilder
     142: dup
     143: invokespecial #107                // Method java/lang/StringBuilder."<init>":()V
     146: ldc           #109                // String Solution for Day 2, Part  I:
     148: invokevirtual #113                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     151: iload_3
     152: invokevirtual #116                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     155: bipush        10
     157: invokevirtual #119                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     160: invokevirtual #123                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     163: getstatic     #129                // Field java/lang/System.out:Ljava/io/PrintStream;
     166: swap
     167: invokevirtual #134                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     170: new           #106                // class java/lang/StringBuilder
     173: dup
     174: invokespecial #107                // Method java/lang/StringBuilder."<init>":()V
     177: ldc           #136                // String Solution for Day 2, Part II:
     179: invokevirtual #113                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     182: iload         4
     184: invokevirtual #116                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     187: bipush        10
     189: invokevirtual #119                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     192: invokevirtual #123                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     195: getstatic     #129                // Field java/lang/System.out:Ljava/io/PrintStream;
     198: swap
     199: invokevirtual #134                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     202: return

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

  private static final kotlin.Unit main$lambda$0();
    Code:
       0: getstatic     #157                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
       3: areturn
}

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

  public final int sumIds(java.util.List<java.lang.String>, java.util.List<io.steinh.aoc.day02.CubeCount>);
    Code:
       0: aload_1
       1: ldc           #16                 // String lines
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #24                 // String bagLimits
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokespecial #28                 // Method analyze:(Ljava/util/List;)Ljava/util/Map;
      17: astore_3
      18: iconst_0
      19: istore        4
      21: aload_3
      22: invokeinterface #34,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      27: invokeinterface #40,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      32: astore        5
      34: aload         5
      36: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          330
      44: aload         5
      46: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: checkcast     #52                 // class java/util/Map$Entry
      54: astore        6
      56: iconst_1
      57: istore        7
      59: aload         6
      61: invokeinterface #55,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      66: checkcast     #57                 // class java/util/List
      69: invokeinterface #58,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      74: astore        8
      76: aload         8
      78: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      83: ifeq          261
      86: aload         8
      88: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: checkcast     #57                 // class java/util/List
      96: astore        9
      98: aload_2
      99: invokeinterface #58,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     104: astore        10
     106: aload         10
     108: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          76
     116: aload         10
     118: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: checkcast     #60                 // class io/steinh/aoc/day02/CubeCount
     126: astore        11
     128: iload         7
     130: ifeq          255
     133: aload         9
     135: checkcast     #62                 // class java/lang/Iterable
     138: astore        12
     140: iconst_0
     141: istore        13
     143: aload         12
     145: instanceof    #64                 // class java/util/Collection
     148: ifeq          168
     151: aload         12
     153: checkcast     #64                 // class java/util/Collection
     156: invokeinterface #67,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     161: ifeq          168
     164: iconst_0
     165: goto          248
     168: aload         12
     170: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     175: astore        14
     177: aload         14
     179: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     184: ifeq          247
     187: aload         14
     189: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     194: astore        15
     196: aload         15
     198: checkcast     #60                 // class io/steinh/aoc/day02/CubeCount
     201: astore        16
     203: iconst_0
     204: istore        17
     206: aload         16
     208: invokevirtual #72                 // Method io/steinh/aoc/day02/CubeCount.getColor:()Ljava/lang/String;
     211: aload         11
     213: invokevirtual #72                 // Method io/steinh/aoc/day02/CubeCount.getColor:()Ljava/lang/String;
     216: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     219: ifeq          239
     222: aload         16
     224: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     227: aload         11
     229: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     232: if_icmpgt     239
     235: iconst_1
     236: goto          240
     239: iconst_0
     240: ifeq          177
     243: iconst_1
     244: goto          248
     247: iconst_0
     248: ifeq          255
     251: iconst_1
     252: goto          256
     255: iconst_0
     256: istore        7
     258: goto          106
     261: iload         7
     263: ifeq          34
     266: new           #82                 // class java/lang/StringBuilder
     269: dup
     270: invokespecial #83                 // Method java/lang/StringBuilder."<init>":()V
     273: ldc           #85                 // String Game
     275: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     278: aload         6
     280: invokeinterface #92,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     285: checkcast     #94                 // class java/lang/Number
     288: invokevirtual #97                 // Method java/lang/Number.intValue:()I
     291: invokevirtual #100                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     294: ldc           #102                // String  is possible\n
     296: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     299: invokevirtual #105                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     302: getstatic     #111                // Field java/lang/System.out:Ljava/io/PrintStream;
     305: swap
     306: invokevirtual #117                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     309: iload         4
     311: aload         6
     313: invokeinterface #92,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     318: checkcast     #94                 // class java/lang/Number
     321: invokevirtual #97                 // Method java/lang/Number.intValue:()I
     324: iadd
     325: istore        4
     327: goto          34
     330: iload         4
     332: ireturn

  public final int powerOfTheFewest(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String lines
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #28                 // Method analyze:(Ljava/util/List;)Ljava/util/Map;
      11: astore_2
      12: aload_0
      13: aload_2
      14: invokespecial #143                // Method getFewest:(Ljava/util/Map;)Ljava/util/Map;
      17: astore_3
      18: iconst_0
      19: istore        4
      21: aload_3
      22: invokeinterface #34,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      27: invokeinterface #40,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      32: astore        5
      34: aload         5
      36: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          283
      44: aload         5
      46: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: checkcast     #52                 // class java/util/Map$Entry
      54: astore        6
      56: aload         6
      58: invokeinterface #55,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      63: checkcast     #62                 // class java/lang/Iterable
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         8
      73: astore        10
      75: new           #145                // class java/util/ArrayList
      78: dup
      79: aload         8
      81: bipush        10
      83: invokestatic  #151                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      86: invokespecial #154                // Method java/util/ArrayList."<init>":(I)V
      89: checkcast     #64                 // class java/util/Collection
      92: astore        11
      94: iconst_0
      95: istore        12
      97: aload         10
      99: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        13
     106: aload         13
     108: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          159
     116: aload         13
     118: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: astore        14
     125: aload         11
     127: aload         14
     129: checkcast     #60                 // class io/steinh/aoc/day02/CubeCount
     132: astore        15
     134: astore        17
     136: iconst_0
     137: istore        16
     139: aload         15
     141: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     144: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: aload         17
     149: swap
     150: invokeinterface #164,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     155: pop
     156: goto          106
     159: aload         11
     161: checkcast     #57                 // class java/util/List
     164: nop
     165: checkcast     #62                 // class java/lang/Iterable
     168: astore        8
     170: nop
     171: iconst_0
     172: istore        9
     174: aload         8
     176: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     181: astore        10
     183: aload         10
     185: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     190: ifne          203
     193: new           #166                // class java/lang/UnsupportedOperationException
     196: dup
     197: ldc           #168                // String Empty collection can\'t be reduced.
     199: invokespecial #171                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     202: athrow
     203: aload         10
     205: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     210: astore        11
     212: aload         10
     214: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     219: ifeq          263
     222: aload         11
     224: aload         10
     226: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     231: checkcast     #94                 // class java/lang/Number
     234: invokevirtual #97                 // Method java/lang/Number.intValue:()I
     237: istore        12
     239: checkcast     #94                 // class java/lang/Number
     242: invokevirtual #97                 // Method java/lang/Number.intValue:()I
     245: istore        13
     247: iconst_0
     248: istore        14
     250: iload         13
     252: iload         12
     254: imul
     255: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     258: astore        11
     260: goto          212
     263: aload         11
     265: checkcast     #94                 // class java/lang/Number
     268: invokevirtual #97                 // Method java/lang/Number.intValue:()I
     271: istore        7
     273: iload         4
     275: iload         7
     277: iadd
     278: istore        4
     280: goto          34
     283: iload         4
     285: ireturn

  private final java.util.Map<java.lang.Integer, java.util.List<io.steinh.aoc.day02.CubeCount>> getFewest(java.util.Map<java.lang.Integer, ? extends java.util.List<? extends java.util.List<io.steinh.aoc.day02.CubeCount>>>);
    Code:
       0: new           #193                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #194                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #30                 // class java/util/Map
      10: astore_2
      11: aload_1
      12: invokeinterface #34,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      17: invokeinterface #40,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          367
      32: aload_3
      33: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: checkcast     #52                 // class java/util/Map$Entry
      41: astore        4
      43: iconst_0
      44: istore        5
      46: iconst_0
      47: istore        6
      49: iconst_0
      50: istore        7
      52: aload         4
      54: invokeinterface #55,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      59: checkcast     #57                 // class java/util/List
      62: invokeinterface #58,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      67: astore        8
      69: aload         8
      71: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          282
      79: aload         8
      81: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: checkcast     #57                 // class java/util/List
      89: astore        9
      91: aload         9
      93: invokeinterface #58,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      98: astore        10
     100: aload         10
     102: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     107: ifeq          69
     110: aload         10
     112: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     117: checkcast     #60                 // class io/steinh/aoc/day02/CubeCount
     120: astore        11
     122: aload         11
     124: invokevirtual #72                 // Method io/steinh/aoc/day02/CubeCount.getColor:()Ljava/lang/String;
     127: astore        12
     129: aload         12
     131: invokevirtual #199                // Method java/lang/String.hashCode:()I
     134: lookupswitch  { // 3
                112785: 168
               3027034: 194
              98619139: 181
               default: 279
          }
     168: aload         12
     170: ldc           #201                // String red
     172: invokevirtual #204                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     175: ifne          207
     178: goto          100
     181: aload         12
     183: ldc           #206                // String green
     185: invokevirtual #204                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     188: ifne          232
     191: goto          100
     194: aload         12
     196: ldc           #208                // String blue
     198: invokevirtual #204                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     201: ifne          257
     204: goto          100
     207: iload         5
     209: aload         11
     211: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     214: if_icmpge     225
     217: aload         11
     219: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     222: goto          227
     225: iload         5
     227: istore        5
     229: goto          100
     232: iload         6
     234: aload         11
     236: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     239: if_icmpge     250
     242: aload         11
     244: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     247: goto          252
     250: iload         6
     252: istore        6
     254: goto          100
     257: iload         7
     259: aload         11
     261: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     264: if_icmpge     275
     267: aload         11
     269: invokevirtual #80                 // Method io/steinh/aoc/day02/CubeCount.getCount:()I
     272: goto          277
     275: iload         7
     277: istore        7
     279: goto          100
     282: aload_2
     283: astore        8
     285: aload         4
     287: invokeinterface #92,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     292: astore        9
     294: iconst_3
     295: anewarray     #60                 // class io/steinh/aoc/day02/CubeCount
     298: astore        10
     300: aload         10
     302: iconst_0
     303: new           #60                 // class io/steinh/aoc/day02/CubeCount
     306: dup
     307: iload         5
     309: ldc           #201                // String red
     311: invokespecial #211                // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     314: aastore
     315: aload         10
     317: iconst_1
     318: new           #60                 // class io/steinh/aoc/day02/CubeCount
     321: dup
     322: iload         6
     324: ldc           #206                // String green
     326: invokespecial #211                // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     329: aastore
     330: aload         10
     332: iconst_2
     333: new           #60                 // class io/steinh/aoc/day02/CubeCount
     336: dup
     337: iload         7
     339: ldc           #208                // String blue
     341: invokespecial #211                // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     344: aastore
     345: aload         10
     347: invokestatic  #215                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     350: astore        10
     352: aload         8
     354: aload         9
     356: aload         10
     358: invokeinterface #219,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     363: pop
     364: goto          23
     367: aload_2
     368: areturn

  private final java.util.Map<java.lang.Integer, java.util.List<java.util.List<io.steinh.aoc.day02.CubeCount>>> analyze(java.util.List<java.lang.String>);
    Code:
       0: new           #193                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #194                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #30                 // class java/util/Map
      10: astore_2
      11: aload_1
      12: invokeinterface #58,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      17: astore_3
      18: aload_3
      19: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          512
      27: aload_3
      28: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #196                // class java/lang/String
      36: astore        4
      38: new           #223                // class kotlin/text/Regex
      41: dup
      42: ldc           #225                // String Game (\\d+)
      44: invokespecial #226                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      47: aload         4
      49: checkcast     #228                // class java/lang/CharSequence
      52: iconst_0
      53: iconst_2
      54: aconst_null
      55: invokestatic  #232                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      58: dup
      59: invokestatic  #235                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      62: invokeinterface #241,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      67: iconst_1
      68: invokeinterface #245,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      73: checkcast     #196                // class java/lang/String
      76: invokestatic  #249                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      79: istore        5
      81: aload         4
      83: checkcast     #228                // class java/lang/CharSequence
      86: iconst_1
      87: anewarray     #196                // class java/lang/String
      90: astore        7
      92: aload         7
      94: iconst_0
      95: ldc           #251                // String :
      97: aastore
      98: aload         7
     100: iconst_0
     101: iconst_0
     102: bipush        6
     104: aconst_null
     105: invokestatic  #257                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     108: invokestatic  #261                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     111: checkcast     #228                // class java/lang/CharSequence
     114: iconst_1
     115: anewarray     #196                // class java/lang/String
     118: astore        7
     120: aload         7
     122: iconst_0
     123: ldc_w         #263                // String ;
     126: aastore
     127: aload         7
     129: iconst_0
     130: iconst_0
     131: bipush        6
     133: aconst_null
     134: invokestatic  #257                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     137: astore        6
     139: invokestatic  #266                // Method kotlin/collections/CollectionsKt.createListBuilder:()Ljava/util/List;
     142: astore        8
     144: aload         8
     146: astore        9
     148: iconst_0
     149: istore        10
     151: aload         6
     153: invokeinterface #58,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     158: astore        11
     160: aload         11
     162: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     167: ifeq          487
     170: aload         11
     172: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     177: checkcast     #196                // class java/lang/String
     180: astore        12
     182: aload         9
     184: invokestatic  #266                // Method kotlin/collections/CollectionsKt.createListBuilder:()Ljava/util/List;
     187: astore        13
     189: aload         13
     191: astore        14
     193: astore        15
     195: iconst_0
     196: istore        16
     198: iconst_0
     199: istore        17
     201: iconst_0
     202: istore        18
     204: iconst_0
     205: istore        19
     207: new           #223                // class kotlin/text/Regex
     210: dup
     211: ldc_w         #268                // String (\\d+) (red|green|blue)
     214: invokespecial #226                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     217: aload         12
     219: checkcast     #228                // class java/lang/CharSequence
     222: iconst_0
     223: iconst_2
     224: aconst_null
     225: invokestatic  #272                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
     228: invokeinterface #275,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     233: astore        20
     235: aload         20
     237: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     242: ifeq          413
     245: aload         20
     247: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     252: checkcast     #237                // class kotlin/text/MatchResult
     255: astore        21
     257: aload         21
     259: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     264: iconst_1
     265: invokeinterface #284,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     270: dup
     271: invokestatic  #235                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     274: invokevirtual #288                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     277: invokestatic  #249                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     280: istore        22
     282: aload         21
     284: invokeinterface #279,  1          // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     289: iconst_2
     290: invokeinterface #284,  2          // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     295: dup
     296: invokestatic  #235                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     299: invokevirtual #288                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     302: astore        23
     304: aload         23
     306: invokevirtual #199                // Method java/lang/String.hashCode:()I
     309: lookupswitch  { // 3
                112785: 344
               3027034: 370
              98619139: 357
               default: 410
          }
     344: aload         23
     346: ldc           #201                // String red
     348: invokevirtual #204                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     351: ifne          383
     354: goto          235
     357: aload         23
     359: ldc           #206                // String green
     361: invokevirtual #204                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     364: ifne          393
     367: goto          235
     370: aload         23
     372: ldc           #208                // String blue
     374: invokevirtual #204                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     377: ifne          403
     380: goto          235
     383: iload         17
     385: iload         22
     387: iadd
     388: istore        17
     390: goto          235
     393: iload         18
     395: iload         22
     397: iadd
     398: istore        18
     400: goto          235
     403: iload         19
     405: iload         22
     407: iadd
     408: istore        19
     410: goto          235
     413: aload         14
     415: new           #60                 // class io/steinh/aoc/day02/CubeCount
     418: dup
     419: iload         17
     421: ldc           #201                // String red
     423: invokespecial #211                // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     426: invokeinterface #289,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     431: pop
     432: aload         14
     434: new           #60                 // class io/steinh/aoc/day02/CubeCount
     437: dup
     438: iload         19
     440: ldc           #208                // String blue
     442: invokespecial #211                // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     445: invokeinterface #289,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     450: pop
     451: aload         14
     453: new           #60                 // class io/steinh/aoc/day02/CubeCount
     456: dup
     457: iload         18
     459: ldc           #206                // String green
     461: invokespecial #211                // Method io/steinh/aoc/day02/CubeCount."<init>":(ILjava/lang/String;)V
     464: invokeinterface #289,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     469: pop
     470: nop
     471: aload         15
     473: aload         13
     475: invokestatic  #293                // Method kotlin/collections/CollectionsKt.build:(Ljava/util/List;)Ljava/util/List;
     478: invokeinterface #289,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     483: pop
     484: goto          160
     487: nop
     488: aload         8
     490: invokestatic  #293                // Method kotlin/collections/CollectionsKt.build:(Ljava/util/List;)Ljava/util/List;
     493: astore        7
     495: aload_2
     496: iload         5
     498: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     501: aload         7
     503: invokeinterface #219,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     508: pop
     509: goto          18
     512: aload_2
     513: areturn
}


package io.steinh.aoc.day05

class Almanac(private val sourceData: Input) {

    fun lowestLocation(): Long {
        val list = mutableListOf<Long>()

        sourceData.seeds.forEach {
            val soil = getSoilForSeed(it)
            val fertilizer = getFertilizerForSoil(soil)
            val water = getWaterForFertilizer(fertilizer)
            val light = getLightForWater(water)
            val temperature = getTemperatureForLight(light)
            val humidity = getHumidityForTemperature(temperature)

            list.add(getLocationForHumidity(humidity))
        }

        list.sort()

        return list.first()
    }

    fun lowestLocationForSeedRanges(): Long {
        var lowestLocationFound = 0L

        sourceData.seeds.chunked(2).forEach { seedRange ->
            for(it in seedRange.first()..(seedRange.first() + seedRange.last())) {
                val soil = getSoilForSeed(it)
                val fertilizer = getFertilizerForSoil(soil)
                val water = getWaterForFertilizer(fertilizer)
                val light = getLightForWater(water)
                val temperature = getTemperatureForLight(light)
                val humidity = getHumidityForTemperature(temperature)
                val location = getLocationForHumidity(humidity)

                lowestLocationFound =
                    if (lowestLocationFound == 0L || location < lowestLocationFound)
                        location
                    else lowestLocationFound
            }
        }

        return lowestLocationFound
    }

    private fun getSoilForSeed(seed: Long) =
        filterFromMapping(seed, sourceData.seedToSoilMappings)

    private fun getFertilizerForSoil(soil: Long) =
        filterFromMapping(soil, sourceData.soilToFertilizerMappings)

    private fun getWaterForFertilizer(fertilizer: Long) =
        filterFromMapping(fertilizer, sourceData.fertilizerToWaterMappings)

    private fun getLightForWater(water: Long) =
        filterFromMapping(water, sourceData.waterToLightMappings)

    private fun getTemperatureForLight(light: Long) =
        filterFromMapping(light, sourceData.lightToTemperatureMappings)

    private fun getHumidityForTemperature(temperature: Long) =
        filterFromMapping(temperature, sourceData.temperatureToHumidityMappings)

    private fun getLocationForHumidity(humidity: Long) =
        filterFromMapping(humidity, sourceData.humidityToLocationMappings)

    private fun filterFromMapping(id: Long, mappings: List<Mapping>): Long =
        mappings
            .filter {
                it.sourceRangeStart.contains(id)
            }.map {
                it.destinationRangeStart.first + (id - it.sourceRangeStart.first)
            }.ifEmpty {
                listOf(id)
            }.first()

}

fun main() {
    val rawInput = {}.javaClass.classLoader?.getResource("day05/input.txt")?.readText()!!
    val inputProcessor = AlmanacInputProcessor()
    val input = inputProcessor.transform(rawInput)

    val instance = Almanac(input)

    val resultOne = instance.lowestLocation()
    println("Result for day 05, part  I: $resultOne")

    val resultTwo = instance.lowestLocationForSeedRanges()
    println("Result for day 05, part II: $resultTwo")
}

Compiled from "Almanac.kt"
public final class io.steinh.aoc.day05.AlmanacKt {
  public static final void main();
    Code:
       0: invokedynamic #25,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function0;
       5: invokevirtual #29                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
       8: invokevirtual #35                 // Method java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader;
      11: dup
      12: ifnull        50
      15: ldc           #37                 // String day05/input.txt
      17: invokevirtual #43                 // Method java/lang/ClassLoader.getResource:(Ljava/lang/String;)Ljava/net/URL;
      20: dup
      21: ifnull        50
      24: astore_3
      25: getstatic     #49                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      28: astore        4
      30: aload_3
      31: invokestatic  #55                 // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      34: astore        5
      36: new           #57                 // class java/lang/String
      39: dup
      40: aload         5
      42: aload         4
      44: invokespecial #61                 // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      47: goto          52
      50: pop
      51: aconst_null
      52: dup
      53: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      56: astore_0
      57: new           #69                 // class io/steinh/aoc/day05/AlmanacInputProcessor
      60: dup
      61: invokespecial #71                 // Method io/steinh/aoc/day05/AlmanacInputProcessor."<init>":()V
      64: astore_1
      65: aload_1
      66: aload_0
      67: invokevirtual #75                 // Method io/steinh/aoc/day05/AlmanacInputProcessor.transform:(Ljava/lang/String;)Lio/steinh/aoc/day05/Input;
      70: astore_2
      71: new           #77                 // class io/steinh/aoc/day05/Almanac
      74: dup
      75: aload_2
      76: invokespecial #80                 // Method io/steinh/aoc/day05/Almanac."<init>":(Lio/steinh/aoc/day05/Input;)V
      79: astore_3
      80: aload_3
      81: invokevirtual #84                 // Method io/steinh/aoc/day05/Almanac.lowestLocation:()J
      84: lstore        4
      86: new           #86                 // class java/lang/StringBuilder
      89: dup
      90: invokespecial #87                 // Method java/lang/StringBuilder."<init>":()V
      93: ldc           #89                 // String Result for day 05, part  I:
      95: invokevirtual #93                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      98: lload         4
     100: invokevirtual #96                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     103: invokevirtual #100                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     106: getstatic     #106                // Field java/lang/System.out:Ljava/io/PrintStream;
     109: swap
     110: invokevirtual #111                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     113: aload_3
     114: invokevirtual #114                // Method io/steinh/aoc/day05/Almanac.lowestLocationForSeedRanges:()J
     117: lstore        6
     119: new           #86                 // class java/lang/StringBuilder
     122: dup
     123: invokespecial #87                 // Method java/lang/StringBuilder."<init>":()V
     126: ldc           #116                // String Result for day 05, part II:
     128: invokevirtual #93                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     131: lload         6
     133: invokevirtual #96                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     136: invokevirtual #100                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     139: getstatic     #106                // Field java/lang/System.out:Ljava/io/PrintStream;
     142: swap
     143: invokevirtual #111                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     146: return

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

  private static final kotlin.Unit main$lambda$0();
    Code:
       0: getstatic     #138                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
       3: areturn
}

Compiled from "Almanac.kt"
public final class io.steinh.aoc.day05.Almanac {
  private final io.steinh.aoc.day05.Input sourceData;

  public io.steinh.aoc.day05.Almanac(io.steinh.aoc.day05.Input);
    Code:
       0: aload_1
       1: ldc           #9                  // String sourceData
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
      15: return

  public final long lowestLocation();
    Code:
       0: new           #27                 // class java/util/ArrayList
       3: dup
       4: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #30                 // class java/util/List
      10: astore_1
      11: aload_0
      12: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
      15: invokevirtual #36                 // Method io/steinh/aoc/day05/Input.getSeeds:()Ljava/util/List;
      18: checkcast     #38                 // class java/lang/Iterable
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        4
      32: aload         4
      34: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          133
      42: aload         4
      44: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        5
      51: aload         5
      53: checkcast     #54                 // class java/lang/Number
      56: invokevirtual #57                 // Method java/lang/Number.longValue:()J
      59: lstore        6
      61: iconst_0
      62: istore        8
      64: aload_0
      65: lload         6
      67: invokespecial #61                 // Method getSoilForSeed:(J)J
      70: lstore        9
      72: aload_0
      73: lload         9
      75: invokespecial #64                 // Method getFertilizerForSoil:(J)J
      78: lstore        11
      80: aload_0
      81: lload         11
      83: invokespecial #67                 // Method getWaterForFertilizer:(J)J
      86: lstore        13
      88: aload_0
      89: lload         13
      91: invokespecial #70                 // Method getLightForWater:(J)J
      94: lstore        15
      96: aload_0
      97: lload         15
      99: invokespecial #73                 // Method getTemperatureForLight:(J)J
     102: lstore        17
     104: aload_0
     105: lload         17
     107: invokespecial #76                 // Method getHumidityForTemperature:(J)J
     110: lstore        19
     112: aload_1
     113: aload_0
     114: lload         19
     116: invokespecial #79                 // Method getLocationForHumidity:(J)J
     119: invokestatic  #85                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     122: invokeinterface #89,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     127: pop
     128: nop
     129: nop
     130: goto          32
     133: nop
     134: aload_1
     135: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     138: aload_1
     139: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     142: checkcast     #54                 // class java/lang/Number
     145: invokevirtual #57                 // Method java/lang/Number.longValue:()J
     148: lreturn

  public final long lowestLocationForSeedRanges();
    Code:
       0: lconst_0
       1: lstore        25
       3: aload_0
       4: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       7: invokevirtual #36                 // Method io/steinh/aoc/day05/Input.getSeeds:()Ljava/util/List;
      10: checkcast     #38                 // class java/lang/Iterable
      13: iconst_2
      14: invokestatic  #121                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      17: checkcast     #38                 // class java/lang/Iterable
      20: astore_1
      21: iconst_0
      22: istore_2
      23: aload_1
      24: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      29: astore_3
      30: aload_3
      31: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          206
      39: aload_3
      40: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        4
      47: aload         4
      49: checkcast     #30                 // class java/util/List
      52: astore        5
      54: iconst_0
      55: istore        6
      57: aload         5
      59: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      62: checkcast     #54                 // class java/lang/Number
      65: invokevirtual #57                 // Method java/lang/Number.longValue:()J
      68: lstore        7
      70: aload         5
      72: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      75: checkcast     #54                 // class java/lang/Number
      78: invokevirtual #57                 // Method java/lang/Number.longValue:()J
      81: aload         5
      83: invokestatic  #124                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      86: checkcast     #54                 // class java/lang/Number
      89: invokevirtual #57                 // Method java/lang/Number.longValue:()J
      92: ladd
      93: lstore        9
      95: lload         7
      97: lload         9
      99: lcmp
     100: ifgt          201
     103: aload_0
     104: lload         7
     106: invokespecial #61                 // Method getSoilForSeed:(J)J
     109: lstore        11
     111: aload_0
     112: lload         11
     114: invokespecial #64                 // Method getFertilizerForSoil:(J)J
     117: lstore        13
     119: aload_0
     120: lload         13
     122: invokespecial #67                 // Method getWaterForFertilizer:(J)J
     125: lstore        15
     127: aload_0
     128: lload         15
     130: invokespecial #70                 // Method getLightForWater:(J)J
     133: lstore        17
     135: aload_0
     136: lload         17
     138: invokespecial #73                 // Method getTemperatureForLight:(J)J
     141: lstore        19
     143: aload_0
     144: lload         19
     146: invokespecial #76                 // Method getHumidityForTemperature:(J)J
     149: lstore        21
     151: aload_0
     152: lload         21
     154: invokespecial #79                 // Method getLocationForHumidity:(J)J
     157: lstore        23
     159: nop
     160: lload         25
     162: lconst_0
     163: lcmp
     164: ifeq          175
     167: lload         23
     169: lload         25
     171: lcmp
     172: ifge          180
     175: lload         23
     177: goto          182
     180: lload         25
     182: lstore        25
     184: lload         7
     186: lload         9
     188: lcmp
     189: ifeq          201
     192: lload         7
     194: lconst_1
     195: ladd
     196: lstore        7
     198: goto          103
     201: nop
     202: nop
     203: goto          30
     206: nop
     207: lload         25
     209: lreturn

  private final long getSoilForSeed(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #131                // Method io/steinh/aoc/day05/Input.getSeedToSoilMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long getFertilizerForSoil(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #139                // Method io/steinh/aoc/day05/Input.getSoilToFertilizerMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long getWaterForFertilizer(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #142                // Method io/steinh/aoc/day05/Input.getFertilizerToWaterMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long getLightForWater(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #145                // Method io/steinh/aoc/day05/Input.getWaterToLightMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long getTemperatureForLight(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #148                // Method io/steinh/aoc/day05/Input.getLightToTemperatureMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long getHumidityForTemperature(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #151                // Method io/steinh/aoc/day05/Input.getTemperatureToHumidityMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long getLocationForHumidity(long);
    Code:
       0: aload_0
       1: lload_1
       2: aload_0
       3: getfield      #21                 // Field sourceData:Lio/steinh/aoc/day05/Input;
       6: invokevirtual #154                // Method io/steinh/aoc/day05/Input.getHumidityToLocationMappings:()Ljava/util/List;
       9: invokespecial #135                // Method filterFromMapping:(JLjava/util/List;)J
      12: lreturn

  private final long filterFromMapping(long, java.util.List<io.steinh.aoc.day05.Mapping>);
    Code:
       0: aload_3
       1: checkcast     #38                 // class java/lang/Iterable
       4: astore        4
       6: nop
       7: iconst_0
       8: istore        5
      10: aload         4
      12: astore        6
      14: new           #27                 // class java/util/ArrayList
      17: dup
      18: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      21: checkcast     #157                // class java/util/Collection
      24: astore        7
      26: iconst_0
      27: istore        8
      29: aload         6
      31: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        9
      38: aload         9
      40: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          92
      48: aload         9
      50: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        10
      57: aload         10
      59: checkcast     #159                // class io/steinh/aoc/day05/Mapping
      62: astore        11
      64: iconst_0
      65: istore        12
      67: aload         11
      69: invokevirtual #163                // Method io/steinh/aoc/day05/Mapping.getSourceRangeStart:()Lkotlin/ranges/LongRange;
      72: lload_1
      73: invokevirtual #169                // Method kotlin/ranges/LongRange.contains:(J)Z
      76: ifeq          38
      79: aload         7
      81: aload         10
      83: invokeinterface #170,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          38
      92: aload         7
      94: checkcast     #30                 // class java/util/List
      97: nop
      98: checkcast     #38                 // class java/lang/Iterable
     101: astore        4
     103: nop
     104: iconst_0
     105: istore        5
     107: aload         4
     109: astore        6
     111: new           #27                 // class java/util/ArrayList
     114: dup
     115: aload         4
     117: bipush        10
     119: invokestatic  #174                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     122: invokespecial #177                // Method java/util/ArrayList."<init>":(I)V
     125: checkcast     #157                // class java/util/Collection
     128: astore        7
     130: iconst_0
     131: istore        8
     133: aload         6
     135: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     140: astore        9
     142: aload         9
     144: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     149: ifeq          209
     152: aload         9
     154: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     159: astore        10
     161: aload         7
     163: aload         10
     165: checkcast     #159                // class io/steinh/aoc/day05/Mapping
     168: astore        11
     170: astore        13
     172: iconst_0
     173: istore        12
     175: aload         11
     177: invokevirtual #180                // Method io/steinh/aoc/day05/Mapping.getDestinationRangeStart:()Lkotlin/ranges/LongRange;
     180: invokevirtual #183                // Method kotlin/ranges/LongRange.getFirst:()J
     183: lload_1
     184: aload         11
     186: invokevirtual #163                // Method io/steinh/aoc/day05/Mapping.getSourceRangeStart:()Lkotlin/ranges/LongRange;
     189: invokevirtual #183                // Method kotlin/ranges/LongRange.getFirst:()J
     192: lsub
     193: ladd
     194: invokestatic  #85                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     197: aload         13
     199: swap
     200: invokeinterface #170,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     205: pop
     206: goto          142
     209: aload         7
     211: checkcast     #30                 // class java/util/List
     214: nop
     215: checkcast     #157                // class java/util/Collection
     218: astore        4
     220: aload         4
     222: invokeinterface #186,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     227: ifeq          243
     230: iconst_0
     231: istore        5
     233: lload_1
     234: invokestatic  #85                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     237: invokestatic  #190                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     240: goto          245
     243: aload         4
     245: checkcast     #30                 // class java/util/List
     248: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     251: checkcast     #54                 // class java/lang/Number
     254: invokevirtual #57                 // Method java/lang/Number.longValue:()J
     257: lreturn
}


package io.steinh.aoc.day05

class AlmanacInputProcessor {

    companion object {
        const val LENGTH_POSITION = 3
    }

    fun transform(input: String): Input {
        return Input(
            extractSeeds(input),
            extractBlockFor("seed-to-soil", input),
            extractBlockFor("soil-to-fertilizer", input),
            extractBlockFor("fertilizer-to-water", input),
            extractBlockFor("water-to-light", input),
            extractBlockFor("light-to-temperature", input),
            extractBlockFor("temperature-to-humidity", input),
            extractBlockFor("humidity-to-location", input)
        )
    }

    private fun extractSeeds(input: String): List<Long> {
        val spaceSeperatedSeeds = "^seeds: ([\\d ]+)\n".toRegex().find(input) ?: return emptyList()

        return spaceSeperatedSeeds.groupValues[1].split(" ").map { it.toLong() }
    }

    private fun extractBlockFor(prefix: String, input: String): List<Mapping> {
        val rawMappings = "$prefix map:.*([\\d \\n]+)".toRegex().findAll(input)

        return rawMappings.flatMap {
            "(\\d+) (\\d+) (\\d+)\\n?".toRegex().findAll(it.groupValues[1])
                .map { mappings -> extractMapping(mappings) }
        }.toList()
    }

    private fun extractMapping(matchResult: MatchResult): Mapping {
        var length = matchResult.groupValues[LENGTH_POSITION].toLong()
        if (length > 0) {
            length -= 1
        }

        val destinationRangeStart = matchResult.groupValues[1].toLong()
        val sourceRangeStart = matchResult.groupValues[2].toLong()
        return Mapping(destinationRangeStart..(destinationRangeStart+length),
            sourceRangeStart..(sourceRangeStart+length))
    }

}

data class Mapping(
    val destinationRangeStart: LongRange,
    val sourceRangeStart: LongRange,
)

data class Input(
    val seeds: List<Long>,
    val seedToSoilMappings: List<Mapping>,
    val soilToFertilizerMappings: List<Mapping>,
    val fertilizerToWaterMappings: List<Mapping>,
    val waterToLightMappings: List<Mapping>,
    val lightToTemperatureMappings: List<Mapping>,
    val temperatureToHumidityMappings: List<Mapping>,
    val humidityToLocationMappings: List<Mapping>,
)

Compiled from "AlmanacInputProcessor.kt"
public final class io.steinh.aoc.day05.AlmanacInputProcessor$Companion {
  private io.steinh.aoc.day05.AlmanacInputProcessor$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public io.steinh.aoc.day05.AlmanacInputProcessor$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #12                 // Method "<init>":()V
       4: return
}

Compiled from "AlmanacInputProcessor.kt"
public final class io.steinh.aoc.day05.AlmanacInputProcessor {
  public static final io.steinh.aoc.day05.AlmanacInputProcessor$Companion Companion;

  public static final int LENGTH_POSITION;

  public io.steinh.aoc.day05.AlmanacInputProcessor();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final io.steinh.aoc.day05.Input transform(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String input
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class io/steinh/aoc/day05/Input
       9: dup
      10: aload_0
      11: aload_1
      12: invokespecial #27                 // Method extractSeeds:(Ljava/lang/String;)Ljava/util/List;
      15: aload_0
      16: ldc           #29                 // String seed-to-soil
      18: aload_1
      19: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      22: aload_0
      23: ldc           #35                 // String soil-to-fertilizer
      25: aload_1
      26: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      29: aload_0
      30: ldc           #37                 // String fertilizer-to-water
      32: aload_1
      33: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      36: aload_0
      37: ldc           #39                 // String water-to-light
      39: aload_1
      40: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      43: aload_0
      44: ldc           #41                 // String light-to-temperature
      46: aload_1
      47: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      50: aload_0
      51: ldc           #43                 // String temperature-to-humidity
      53: aload_1
      54: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      57: aload_0
      58: ldc           #45                 // String humidity-to-location
      60: aload_1
      61: invokespecial #33                 // Method extractBlockFor:(Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;
      64: invokespecial #48                 // Method io/steinh/aoc/day05/Input."<init>":(Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;)V
      67: areturn

  private final java.util.List<java.lang.Long> extractSeeds(java.lang.String);
    Code:
       0: new           #52                 // class kotlin/text/Regex
       3: dup
       4: ldc           #54                 // String ^seeds: ([\\d ]+)\n
       6: invokespecial #57                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: aload_1
      10: checkcast     #59                 // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #63                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      19: dup
      20: ifnonnull     28
      23: pop
      24: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      27: areturn
      28: astore_2
      29: aload_2
      30: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      35: iconst_1
      36: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      41: checkcast     #59                 // class java/lang/CharSequence
      44: iconst_1
      45: anewarray     #82                 // class java/lang/String
      48: astore_3
      49: aload_3
      50: iconst_0
      51: ldc           #84                 // String
      53: aastore
      54: aload_3
      55: iconst_0
      56: iconst_0
      57: bipush        6
      59: aconst_null
      60: invokestatic  #90                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      63: checkcast     #92                 // class java/lang/Iterable
      66: astore_3
      67: iconst_0
      68: istore        4
      70: aload_3
      71: astore        5
      73: new           #94                 // class java/util/ArrayList
      76: dup
      77: aload_3
      78: bipush        10
      80: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      83: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
      86: checkcast     #103                // class java/util/Collection
      89: astore        6
      91: iconst_0
      92: istore        7
      94: aload         5
      96: invokeinterface #107,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     101: astore        8
     103: aload         8
     105: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     110: ifeq          157
     113: aload         8
     115: invokeinterface #117,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: astore        9
     122: aload         6
     124: aload         9
     126: checkcast     #82                 // class java/lang/String
     129: astore        10
     131: astore        12
     133: iconst_0
     134: istore        11
     136: aload         10
     138: invokestatic  #123                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     141: nop
     142: invokestatic  #127                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     145: aload         12
     147: swap
     148: invokeinterface #131,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     153: pop
     154: goto          103
     157: aload         6
     159: checkcast     #76                 // class java/util/List
     162: nop
     163: areturn

  private final java.util.List<io.steinh.aoc.day05.Mapping> extractBlockFor(java.lang.String, java.lang.String);
    Code:
       0: new           #52                 // class kotlin/text/Regex
       3: dup
       4: new           #148                // class java/lang/StringBuilder
       7: dup
       8: invokespecial #149                // Method java/lang/StringBuilder."<init>":()V
      11: aload_1
      12: invokevirtual #153                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      15: ldc           #155                // String  map:.*([\\d \\n]+)
      17: invokevirtual #153                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      20: invokevirtual #159                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      23: invokespecial #57                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      26: aload_2
      27: checkcast     #59                 // class java/lang/CharSequence
      30: iconst_0
      31: iconst_2
      32: aconst_null
      33: invokestatic  #163                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      36: astore_3
      37: aload_3
      38: aload_0
      39: invokedynamic #183,  0            // InvokeDynamic #0:invoke:(Lio/steinh/aoc/day05/AlmanacInputProcessor;)Lkotlin/jvm/functions/Function1;
      44: invokestatic  #189                // Method kotlin/sequences/SequencesKt.flatMap:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      47: invokestatic  #193                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      50: areturn

  private final io.steinh.aoc.day05.Mapping extractMapping(kotlin.text.MatchResult);
    Code:
       0: aload_1
       1: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
       6: iconst_3
       7: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      12: checkcast     #82                 // class java/lang/String
      15: invokestatic  #123                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      18: lstore_2
      19: lload_2
      20: lconst_0
      21: lcmp
      22: ifle          29
      25: lload_2
      26: lconst_1
      27: lsub
      28: lstore_2
      29: aload_1
      30: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      35: iconst_1
      36: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      41: checkcast     #82                 // class java/lang/String
      44: invokestatic  #123                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      47: lstore        4
      49: aload_1
      50: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      55: iconst_2
      56: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      61: checkcast     #82                 // class java/lang/String
      64: invokestatic  #123                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      67: lstore        6
      69: new           #200                // class io/steinh/aoc/day05/Mapping
      72: dup
      73: new           #202                // class kotlin/ranges/LongRange
      76: dup
      77: lload         4
      79: lload         4
      81: lload_2
      82: ladd
      83: invokespecial #205                // Method kotlin/ranges/LongRange."<init>":(JJ)V
      86: new           #202                // class kotlin/ranges/LongRange
      89: dup
      90: lload         6
      92: lload         6
      94: lload_2
      95: ladd
      96: invokespecial #205                // Method kotlin/ranges/LongRange."<init>":(JJ)V
      99: invokespecial #208                // Method io/steinh/aoc/day05/Mapping."<init>":(Lkotlin/ranges/LongRange;Lkotlin/ranges/LongRange;)V
     102: areturn

  private static final io.steinh.aoc.day05.Mapping extractBlockFor$lambda$2$lambda$1(io.steinh.aoc.day05.AlmanacInputProcessor, kotlin.text.MatchResult);
    Code:
       0: aload_1
       1: ldc           #217                // String mappings
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #219                // Method extractMapping:(Lkotlin/text/MatchResult;)Lio/steinh/aoc/day05/Mapping;
      11: areturn

  private static final kotlin.sequences.Sequence extractBlockFor$lambda$2(io.steinh.aoc.day05.AlmanacInputProcessor, kotlin.text.MatchResult);
    Code:
       0: aload_1
       1: ldc           #221                // String it
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #52                 // class kotlin/text/Regex
       9: dup
      10: ldc           #223                // String (\\d+) (\\d+) (\\d+)\\n?
      12: invokespecial #57                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: aload_1
      16: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      21: iconst_1
      22: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #59                 // class java/lang/CharSequence
      30: iconst_0
      31: iconst_2
      32: aconst_null
      33: invokestatic  #163                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      36: aload_0
      37: invokedynamic #228,  0            // InvokeDynamic #1:invoke:(Lio/steinh/aoc/day05/AlmanacInputProcessor;)Lkotlin/jvm/functions/Function1;
      42: invokestatic  #231                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      45: areturn

  static {};
    Code:
       0: new           #234                // class io/steinh/aoc/day05/AlmanacInputProcessor$Companion
       3: dup
       4: aconst_null
       5: invokespecial #237                // Method io/steinh/aoc/day05/AlmanacInputProcessor$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #241                // Field Companion:Lio/steinh/aoc/day05/AlmanacInputProcessor$Companion;
      11: return
}


package com.hawkeye.movement.utils

import kotlin.math.PI

fun cos(angle: AngleMeasure): Float = kotlin.math.cos(angle.radian())
fun sin(angle: AngleMeasure): Float = kotlin.math.sin(angle.radian())

fun abs(angle: AngleMeasure): AngleMeasure = Degree(kotlin.math.abs(angle.degree()))
fun sign(angle: AngleMeasure): Float {
    return if (angle > Degree(0f)) {
        1f
    } else if (angle < Degree(0f)) {
        -1f
    } else {
        0f
    }
}

fun min(a: AngleMeasure, b: AngleMeasure): AngleMeasure =
    Degree(kotlin.math.min(a.degree(), b.degree()))

fun max(a: AngleMeasure, b: AngleMeasure): AngleMeasure =
    Degree(kotlin.math.max(a.degree(), b.degree()))

interface AngleMeasure : Comparable<AngleMeasure> {
    fun degree(): Float {
        return this.radian() * 180.0f / PI.toFloat()
    }
    fun radian(): Float {
        return this.degree() * PI.toFloat() / 180.0f
    }

    override operator fun compareTo(angle: AngleMeasure): Int {
        val deltaAngle = this.degree() - angle.degree()
        if (deltaAngle < -eps) {
            return -1
        }
        if (deltaAngle > eps) {
            return 1
        }
        return 0
    }

    operator fun plus(angle: AngleMeasure): AngleMeasure {
        return Degree(this.degree() + angle.degree())
    }

    operator fun minus(angle: AngleMeasure): AngleMeasure {
        return Degree(this.degree() - angle.degree())
    }

    operator fun times(factor: Float): AngleMeasure {
        return Degree(this.degree() * factor)
    }

    operator fun div(factor: Float): AngleMeasure {
        return Degree(this.degree() / factor)
    }
    companion object {
        private const val eps = 0.00001f
    }
}

class Radian(private val angle: Float) : AngleMeasure {
    override fun degree(): Float = angle * 180.0f / PI.toFloat()

    override fun radian(): Float = angle
}

class Degree(private val angle: Float) : AngleMeasure {
    override fun degree(): Float = angle

    override fun radian(): Float = angle * PI.toFloat() / 180.0f
}

Compiled from "AngleMeasure.kt"
public final class com.hawkeye.movement.utils.AngleMeasure$DefaultImpls {
  public static float degree(com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: invokeinterface #13,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.radian:()F
       6: ldc           #14                 // float 180.0f
       8: fmul
       9: ldc           #15                 // float 3.1415927f
      11: fdiv
      12: freturn

  public static float radian(com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
       6: ldc           #15                 // float 3.1415927f
       8: fmul
       9: ldc           #14                 // float 180.0f
      11: fdiv
      12: freturn

  public static int compareTo(com.hawkeye.movement.utils.AngleMeasure, com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_1
       1: ldc           #23                 // String angle
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      12: aload_1
      13: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      18: fsub
      19: fstore_2
      20: fload_2
      21: ldc           #30                 // float -1.0E-5f
      23: fcmpg
      24: ifge          29
      27: iconst_m1
      28: ireturn
      29: fload_2
      30: ldc           #31                 // float 1.0E-5f
      32: fcmpl
      33: ifle          38
      36: iconst_1
      37: ireturn
      38: iconst_0
      39: ireturn

  public static com.hawkeye.movement.utils.AngleMeasure plus(com.hawkeye.movement.utils.AngleMeasure, com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_1
       1: ldc           #23                 // String angle
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #37                 // class com/hawkeye/movement/utils/Degree
       9: dup
      10: aload_0
      11: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      16: aload_1
      17: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      22: fadd
      23: invokespecial #41                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      26: checkcast     #9                  // class com/hawkeye/movement/utils/AngleMeasure
      29: areturn

  public static com.hawkeye.movement.utils.AngleMeasure minus(com.hawkeye.movement.utils.AngleMeasure, com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_1
       1: ldc           #23                 // String angle
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #37                 // class com/hawkeye/movement/utils/Degree
       9: dup
      10: aload_0
      11: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      16: aload_1
      17: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      22: fsub
      23: invokespecial #41                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      26: checkcast     #9                  // class com/hawkeye/movement/utils/AngleMeasure
      29: areturn

  public static com.hawkeye.movement.utils.AngleMeasure times(com.hawkeye.movement.utils.AngleMeasure, float);
    Code:
       0: new           #37                 // class com/hawkeye/movement/utils/Degree
       3: dup
       4: aload_0
       5: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      10: fload_1
      11: fmul
      12: invokespecial #41                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      15: checkcast     #9                  // class com/hawkeye/movement/utils/AngleMeasure
      18: areturn

  public static com.hawkeye.movement.utils.AngleMeasure div(com.hawkeye.movement.utils.AngleMeasure, float);
    Code:
       0: new           #37                 // class com/hawkeye/movement/utils/Degree
       3: dup
       4: aload_0
       5: invokeinterface #19,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      10: fload_1
      11: fdiv
      12: invokespecial #41                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      15: checkcast     #9                  // class com/hawkeye/movement/utils/AngleMeasure
      18: areturn
}

Compiled from "AngleMeasure.kt"
public interface com.hawkeye.movement.utils.AngleMeasure extends java.lang.Comparable<com.hawkeye.movement.utils.AngleMeasure> {
  public static final com.hawkeye.movement.utils.AngleMeasure$Companion Companion;

  public abstract float degree();

  public abstract float radian();

  public abstract int compareTo(com.hawkeye.movement.utils.AngleMeasure);

  public abstract com.hawkeye.movement.utils.AngleMeasure plus(com.hawkeye.movement.utils.AngleMeasure);

  public abstract com.hawkeye.movement.utils.AngleMeasure minus(com.hawkeye.movement.utils.AngleMeasure);

  public abstract com.hawkeye.movement.utils.AngleMeasure times(float);

  public abstract com.hawkeye.movement.utils.AngleMeasure div(float);

  static {};
    Code:
       0: getstatic     #27                 // Field com/hawkeye/movement/utils/AngleMeasure$Companion.$$INSTANCE:Lcom/hawkeye/movement/utils/AngleMeasure$Companion;
       3: putstatic     #30                 // Field Companion:Lcom/hawkeye/movement/utils/AngleMeasure$Companion;
       6: return
}

Compiled from "AngleMeasure.kt"
public final class com.hawkeye.movement.utils.AngleMeasureKt {
  public static final float cos(com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: ldc           #9                  // String angle
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #21,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.radian:()F
      12: f2d
      13: invokestatic  #26                 // Method java/lang/Math.cos:(D)D
      16: d2f
      17: freturn

  public static final float sin(com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: ldc           #9                  // String angle
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #21,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.radian:()F
      12: f2d
      13: invokestatic  #30                 // Method java/lang/Math.sin:(D)D
      16: d2f
      17: freturn

  public static final com.hawkeye.movement.utils.AngleMeasure abs(com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: ldc           #9                  // String angle
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #34                 // class com/hawkeye/movement/utils/Degree
       9: dup
      10: aload_0
      11: invokeinterface #37,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      16: invokestatic  #40                 // Method java/lang/Math.abs:(F)F
      19: invokespecial #44                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      22: checkcast     #17                 // class com/hawkeye/movement/utils/AngleMeasure
      25: areturn

  public static final float sign(com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: ldc           #9                  // String angle
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: new           #34                 // class com/hawkeye/movement/utils/Degree
      10: dup
      11: fconst_0
      12: invokespecial #44                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      15: checkcast     #17                 // class com/hawkeye/movement/utils/AngleMeasure
      18: invokeinterface #49,  2           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.compareTo:(Lcom/hawkeye/movement/utils/AngleMeasure;)I
      23: ifle          30
      26: fconst_1
      27: goto          56
      30: aload_0
      31: new           #34                 // class com/hawkeye/movement/utils/Degree
      34: dup
      35: fconst_0
      36: invokespecial #44                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      39: checkcast     #17                 // class com/hawkeye/movement/utils/AngleMeasure
      42: invokeinterface #49,  2           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.compareTo:(Lcom/hawkeye/movement/utils/AngleMeasure;)I
      47: ifge          55
      50: ldc           #50                 // float -1.0f
      52: goto          56
      55: fconst_0
      56: freturn

  public static final com.hawkeye.movement.utils.AngleMeasure min(com.hawkeye.movement.utils.AngleMeasure, com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: ldc           #54                 // String a
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #56                 // String b
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #34                 // class com/hawkeye/movement/utils/Degree
      15: dup
      16: aload_0
      17: invokeinterface #37,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      22: aload_1
      23: invokeinterface #37,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      28: invokestatic  #59                 // Method java/lang/Math.min:(FF)F
      31: invokespecial #44                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      34: checkcast     #17                 // class com/hawkeye/movement/utils/AngleMeasure
      37: areturn

  public static final com.hawkeye.movement.utils.AngleMeasure max(com.hawkeye.movement.utils.AngleMeasure, com.hawkeye.movement.utils.AngleMeasure);
    Code:
       0: aload_0
       1: ldc           #54                 // String a
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #56                 // String b
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #34                 // class com/hawkeye/movement/utils/Degree
      15: dup
      16: aload_0
      17: invokeinterface #37,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      22: aload_1
      23: invokeinterface #37,  1           // InterfaceMethod com/hawkeye/movement/utils/AngleMeasure.degree:()F
      28: invokestatic  #62                 // Method java/lang/Math.max:(FF)F
      31: invokespecial #44                 // Method com/hawkeye/movement/utils/Degree."<init>":(F)V
      34: checkcast     #17                 // class com/hawkeye/movement/utils/AngleMeasure
      37: areturn
}

Compiled from "AngleMeasure.kt"
public final class com.hawkeye.movement.utils.AngleMeasure$Companion {
  static final com.hawkeye.movement.utils.AngleMeasure$Companion $$INSTANCE;

  private static final float eps;

  private com.hawkeye.movement.utils.AngleMeasure$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  static {};
    Code:
       0: new           #2                  // class com/hawkeye/movement/utils/AngleMeasure$Companion
       3: dup
       4: invokespecial #12                 // Method "<init>":()V
       7: putstatic     #15                 // Field $$INSTANCE:Lcom/hawkeye/movement/utils/AngleMeasure$Companion;
      10: return
}