package io.steinh.aoc.day04

class Scratchcard {
    fun calculatePoints(lines: List<String>) = getMatchingNumbers(lines).sum()

    fun calculateNumberOfCardsWon(lines: List<String>): Int {
        val givenNumberOfCards = lines.size
        val numberOfCards = initCardStack(givenNumberOfCards)

        for (line in lines) {
            val firstSplit = line.split(":")
            val cardId = firstSplit[0].substringAfter("Card ").trim().toInt()
            println("Processing card #$cardId:")

            val instancesOfThisCard = numberOfCards[cardId]
            println("\texisting instances: $instancesOfThisCard")

            val numberOfMatches = extractWinningNumbers(firstSplit[1]).size
            println("\tno. matching numbers: $numberOfMatches")

            if (numberOfMatches == 0) {
                println("\tNo matches, continuing to next card. Done processing card #$cardId")
                continue
            }

            val start = cardId + 1
            if (start <= givenNumberOfCards) {
                val end =
                    if (cardId + numberOfMatches < givenNumberOfCards)
                        cardId + numberOfMatches
                    else
                        givenNumberOfCards

                println("\tWill add $instancesOfThisCard instances to cards ##" + (start..end))
                for (i in start..end) {
                    numberOfCards[i] = numberOfCards[i]!! + instancesOfThisCard!!
                    println("\t\tAdded $instancesOfThisCard to card #$i. This card has now ${numberOfCards[i]} " +
                            "instances.")
                }
            }
            println("\tDone processing card $cardId\n")
        }

        return numberOfCards
            .map { it.value }
            .sum()
    }

    private fun initCardStack(givenNumberOfCards: Int): MutableMap<Int, Int> {
        val result = mutableMapOf<Int, Int>()
        for (i in 1..givenNumberOfCards) {
            result[i] = 1
        }

        return result
    }

    private fun getMatchingNumbers(lines: List<String>) = buildList {
        for (line in lines) {
            val firstSplit = line.split(":")

            val intersection = extractWinningNumbers(firstSplit[1])

            var result = 0
            for (i in 1..intersection.size) {
                result = if (i == 1) 1 else result * 2
            }

            add(result)
        }
    }

    private fun extractWinningNumbers(matchesAndGuesses: String): Set<Int> {
        val winnersAndGuesses = matchesAndGuesses.split("|")
        val winners = winnersAndGuesses[0].split(" ")
            .filter { it.isNotEmpty() }
            .map { it.toInt() }

        val guesses = winnersAndGuesses[1].split(" ")
            .filter { it.isNotEmpty() }
            .map { it.toInt() }

        val intersection = winners.intersect(guesses.toSet())
        return intersection
    }
}

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

    val scratchcard = Scratchcard()
    val resultPart1 = scratchcard.calculatePoints(lines)
    val resultPart2 = scratchcard.calculateNumberOfCardsWon(lines)

    println("Result day 04, part  I: $resultPart1")
    println("Result day 04, part II: $resultPart2")
}

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

  public final int calculatePoints(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 #26                 // Method getMatchingNumbers:(Ljava/util/List;)Ljava/util/List;
      11: checkcast     #28                 // class java/lang/Iterable
      14: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      17: ireturn

  public final int calculateNumberOfCardsWon(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_1
       7: invokeinterface #42,  1           // InterfaceMethod java/util/List.size:()I
      12: istore_2
      13: aload_0
      14: iload_2
      15: invokespecial #46                 // Method initCardStack:(I)Ljava/util/Map;
      18: astore_3
      19: aload_1
      20: invokeinterface #50,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      25: astore        4
      27: aload         4
      29: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          519
      37: aload         4
      39: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: checkcast     #62                 // class java/lang/String
      47: astore        5
      49: aload         5
      51: checkcast     #64                 // class java/lang/CharSequence
      54: iconst_1
      55: anewarray     #62                 // class java/lang/String
      58: astore        7
      60: aload         7
      62: iconst_0
      63: ldc           #66                 // String :
      65: aastore
      66: aload         7
      68: iconst_0
      69: iconst_0
      70: bipush        6
      72: aconst_null
      73: invokestatic  #72                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      76: astore        6
      78: nop
      79: aload         6
      81: iconst_0
      82: invokeinterface #76,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      87: checkcast     #62                 // class java/lang/String
      90: ldc           #78                 // String Card
      92: aconst_null
      93: iconst_2
      94: aconst_null
      95: invokestatic  #82                 // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      98: checkcast     #64                 // class java/lang/CharSequence
     101: invokestatic  #86                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     104: invokevirtual #90                 // Method java/lang/Object.toString:()Ljava/lang/String;
     107: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     110: istore        7
     112: new           #98                 // class java/lang/StringBuilder
     115: dup
     116: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     119: ldc           #101                // String Processing card #
     121: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     124: iload         7
     126: invokevirtual #108                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     129: bipush        58
     131: invokevirtual #111                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     134: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     137: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     140: swap
     141: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     144: aload_3
     145: iload         7
     147: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     150: invokeinterface #133,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     155: checkcast     #92                 // class java/lang/Integer
     158: astore        8
     160: new           #98                 // class java/lang/StringBuilder
     163: dup
     164: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     167: ldc           #135                // String \texisting instances:
     169: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     172: aload         8
     174: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     177: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     180: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     183: swap
     184: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     187: aload_0
     188: aload         6
     190: iconst_1
     191: invokeinterface #76,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     196: checkcast     #62                 // class java/lang/String
     199: invokespecial #142                // Method extractWinningNumbers:(Ljava/lang/String;)Ljava/util/Set;
     202: invokeinterface #145,  1          // InterfaceMethod java/util/Set.size:()I
     207: istore        9
     209: new           #98                 // class java/lang/StringBuilder
     212: dup
     213: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     216: ldc           #147                // String \tno. matching numbers:
     218: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     221: iload         9
     223: invokevirtual #108                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     226: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     229: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     232: swap
     233: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     236: iload         9
     238: ifne          271
     241: new           #98                 // class java/lang/StringBuilder
     244: dup
     245: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     248: ldc           #149                // String \tNo matches, continuing to next card. Done processing card #
     250: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     253: iload         7
     255: invokevirtual #108                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     258: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     261: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     264: swap
     265: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     268: goto          27
     271: iload         7
     273: iconst_1
     274: iadd
     275: istore        10
     277: iload         10
     279: iload_2
     280: if_icmpgt     484
     283: iload         7
     285: iload         9
     287: iadd
     288: iload_2
     289: if_icmpge     300
     292: iload         7
     294: iload         9
     296: iadd
     297: goto          301
     300: iload_2
     301: istore        11
     303: new           #98                 // class java/lang/StringBuilder
     306: dup
     307: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     310: ldc           #151                // String \tWill add
     312: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     315: aload         8
     317: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     320: ldc           #153                // String  instances to cards ##
     322: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     325: new           #155                // class kotlin/ranges/IntRange
     328: dup
     329: iload         10
     331: iload         11
     333: invokespecial #158                // Method kotlin/ranges/IntRange."<init>":(II)V
     336: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     339: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     342: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     345: swap
     346: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     349: iload         10
     351: istore        12
     353: iload         12
     355: iload         11
     357: if_icmpgt     484
     360: iload         12
     362: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     365: astore        13
     367: aload_3
     368: aload         13
     370: aload_3
     371: iload         12
     373: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     376: invokeinterface #133,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     381: dup
     382: invokestatic  #161                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     385: checkcast     #163                // class java/lang/Number
     388: invokevirtual #166                // Method java/lang/Number.intValue:()I
     391: aload         8
     393: dup
     394: invokestatic  #161                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     397: invokevirtual #167                // Method java/lang/Integer.intValue:()I
     400: iadd
     401: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     404: invokeinterface #171,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     409: pop
     410: new           #98                 // class java/lang/StringBuilder
     413: dup
     414: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     417: ldc           #173                // String \t\tAdded
     419: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     422: aload         8
     424: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     427: ldc           #175                // String  to card #
     429: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     432: iload         12
     434: invokevirtual #108                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     437: ldc           #177                // String . This card has now
     439: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     442: aload_3
     443: iload         12
     445: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     448: invokeinterface #133,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     453: invokevirtual #138                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     456: ldc           #179                // String  instances.
     458: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     461: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     464: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     467: swap
     468: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     471: iload         12
     473: iload         11
     475: if_icmpeq     484
     478: iinc          12, 1
     481: goto          360
     484: new           #98                 // class java/lang/StringBuilder
     487: dup
     488: invokespecial #99                 // Method java/lang/StringBuilder."<init>":()V
     491: ldc           #181                // String \tDone processing card
     493: invokevirtual #105                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     496: iload         7
     498: invokevirtual #108                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     501: bipush        10
     503: invokevirtual #111                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     506: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     509: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     512: swap
     513: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     516: goto          27
     519: aload_3
     520: astore        4
     522: nop
     523: iconst_0
     524: istore        5
     526: aload         4
     528: astore        6
     530: new           #183                // class java/util/ArrayList
     533: dup
     534: aload         4
     536: invokeinterface #184,  1          // InterfaceMethod java/util/Map.size:()I
     541: invokespecial #187                // Method java/util/ArrayList."<init>":(I)V
     544: checkcast     #189                // class java/util/Collection
     547: astore        7
     549: iconst_0
     550: istore        8
     552: aload         6
     554: invokeinterface #193,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     559: invokeinterface #194,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     564: astore        9
     566: aload         9
     568: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     573: ifeq          627
     576: aload         9
     578: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     583: checkcast     #196                // class java/util/Map$Entry
     586: astore        10
     588: aload         7
     590: aload         10
     592: astore        11
     594: astore        14
     596: iconst_0
     597: istore        12
     599: aload         11
     601: invokeinterface #199,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     606: checkcast     #163                // class java/lang/Number
     609: invokevirtual #166                // Method java/lang/Number.intValue:()I
     612: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     615: aload         14
     617: swap
     618: invokeinterface #203,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     623: pop
     624: goto          566
     627: aload         7
     629: checkcast     #38                 // class java/util/List
     632: nop
     633: checkcast     #28                 // class java/lang/Iterable
     636: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     639: ireturn

  private final java.util.Map<java.lang.Integer, java.lang.Integer> initCardStack(int);
    Code:
       0: new           #230                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #231                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #130                // class java/util/Map
      10: astore_2
      11: iconst_1
      12: istore_3
      13: iload_3
      14: iload_1
      15: if_icmpgt     48
      18: iload_3
      19: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      22: astore        4
      24: aload_2
      25: aload         4
      27: iconst_1
      28: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      31: invokeinterface #171,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      36: pop
      37: iload_3
      38: iload_1
      39: if_icmpeq     48
      42: iinc          3, 1
      45: goto          18
      48: aload_2
      49: areturn

  private final java.util.List<java.lang.Integer> getMatchingNumbers(java.util.List<java.lang.String>);
    Code:
       0: invokestatic  #237                // Method kotlin/collections/CollectionsKt.createListBuilder:()Ljava/util/List;
       3: astore_2
       4: aload_2
       5: astore_3
       6: iconst_0
       7: istore        4
       9: aload_1
      10: invokeinterface #50,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      15: astore        5
      17: aload         5
      19: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          151
      27: aload         5
      29: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: checkcast     #62                 // class java/lang/String
      37: astore        6
      39: aload         6
      41: checkcast     #64                 // class java/lang/CharSequence
      44: iconst_1
      45: anewarray     #62                 // class java/lang/String
      48: astore        7
      50: aload         7
      52: iconst_0
      53: ldc           #66                 // String :
      55: aastore
      56: aload         7
      58: iconst_0
      59: iconst_0
      60: bipush        6
      62: aconst_null
      63: invokestatic  #72                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      66: astore        8
      68: aload_0
      69: aload         8
      71: iconst_1
      72: invokeinterface #76,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      77: checkcast     #62                 // class java/lang/String
      80: invokespecial #142                // Method extractWinningNumbers:(Ljava/lang/String;)Ljava/util/Set;
      83: astore        7
      85: iconst_0
      86: istore        9
      88: iconst_1
      89: istore        10
      91: aload         7
      93: invokeinterface #145,  1          // InterfaceMethod java/util/Set.size:()I
      98: istore        11
     100: iload         10
     102: iload         11
     104: if_icmpgt     136
     107: iload         10
     109: iconst_1
     110: if_icmpne     117
     113: iconst_1
     114: goto          121
     117: iload         9
     119: iconst_2
     120: imul
     121: istore        9
     123: iload         10
     125: iload         11
     127: if_icmpeq     136
     130: iinc          10, 1
     133: goto          107
     136: aload_3
     137: iload         9
     139: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     142: invokeinterface #238,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     147: pop
     148: goto          17
     151: nop
     152: aload_2
     153: invokestatic  #241                // Method kotlin/collections/CollectionsKt.build:(Ljava/util/List;)Ljava/util/List;
     156: areturn

  private final java.util.Set<java.lang.Integer> extractWinningNumbers(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #64                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #62                 // class java/lang/String
       8: astore_3
       9: aload_3
      10: iconst_0
      11: ldc           #248                // String |
      13: aastore
      14: aload_3
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #72                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: astore_2
      24: aload_2
      25: iconst_0
      26: invokeinterface #76,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      31: checkcast     #64                 // class java/lang/CharSequence
      34: iconst_1
      35: anewarray     #62                 // class java/lang/String
      38: astore        4
      40: aload         4
      42: iconst_0
      43: ldc           #250                // String
      45: aastore
      46: aload         4
      48: iconst_0
      49: iconst_0
      50: bipush        6
      52: aconst_null
      53: invokestatic  #72                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      56: checkcast     #28                 // class java/lang/Iterable
      59: astore        4
      61: nop
      62: iconst_0
      63: istore        5
      65: aload         4
      67: astore        6
      69: new           #183                // class java/util/ArrayList
      72: dup
      73: invokespecial #251                // Method java/util/ArrayList."<init>":()V
      76: checkcast     #189                // class java/util/Collection
      79: astore        7
      81: iconst_0
      82: istore        8
      84: aload         6
      86: invokeinterface #252,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      91: astore        9
      93: aload         9
      95: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     100: ifeq          157
     103: aload         9
     105: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     110: astore        10
     112: aload         10
     114: checkcast     #62                 // class java/lang/String
     117: astore        11
     119: iconst_0
     120: istore        12
     122: aload         11
     124: checkcast     #64                 // class java/lang/CharSequence
     127: invokeinterface #255,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     132: ifle          139
     135: iconst_1
     136: goto          140
     139: iconst_0
     140: nop
     141: ifeq          93
     144: aload         7
     146: aload         10
     148: invokeinterface #203,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     153: pop
     154: goto          93
     157: aload         7
     159: checkcast     #38                 // class java/util/List
     162: nop
     163: checkcast     #28                 // class java/lang/Iterable
     166: astore        4
     168: nop
     169: iconst_0
     170: istore        5
     172: aload         4
     174: astore        6
     176: new           #183                // class java/util/ArrayList
     179: dup
     180: aload         4
     182: bipush        10
     184: invokestatic  #259                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     187: invokespecial #187                // Method java/util/ArrayList."<init>":(I)V
     190: checkcast     #189                // class java/util/Collection
     193: astore        7
     195: iconst_0
     196: istore        8
     198: aload         6
     200: invokeinterface #252,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     205: astore        9
     207: aload         9
     209: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     214: ifeq          261
     217: aload         9
     219: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     224: astore        10
     226: aload         7
     228: aload         10
     230: checkcast     #62                 // class java/lang/String
     233: astore        11
     235: astore        14
     237: iconst_0
     238: istore        12
     240: aload         11
     242: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     245: nop
     246: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     249: aload         14
     251: swap
     252: invokeinterface #203,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     257: pop
     258: goto          207
     261: aload         7
     263: checkcast     #38                 // class java/util/List
     266: nop
     267: astore_3
     268: aload_2
     269: iconst_1
     270: invokeinterface #76,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     275: checkcast     #64                 // class java/lang/CharSequence
     278: iconst_1
     279: anewarray     #62                 // class java/lang/String
     282: astore        5
     284: aload         5
     286: iconst_0
     287: ldc           #250                // String
     289: aastore
     290: aload         5
     292: iconst_0
     293: iconst_0
     294: bipush        6
     296: aconst_null
     297: invokestatic  #72                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     300: checkcast     #28                 // class java/lang/Iterable
     303: astore        5
     305: nop
     306: iconst_0
     307: istore        6
     309: aload         5
     311: astore        7
     313: new           #183                // class java/util/ArrayList
     316: dup
     317: invokespecial #251                // Method java/util/ArrayList."<init>":()V
     320: checkcast     #189                // class java/util/Collection
     323: astore        8
     325: iconst_0
     326: istore        9
     328: aload         7
     330: invokeinterface #252,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     335: astore        10
     337: aload         10
     339: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     344: ifeq          401
     347: aload         10
     349: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     354: astore        11
     356: aload         11
     358: checkcast     #62                 // class java/lang/String
     361: astore        12
     363: iconst_0
     364: istore        13
     366: aload         12
     368: checkcast     #64                 // class java/lang/CharSequence
     371: invokeinterface #255,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     376: ifle          383
     379: iconst_1
     380: goto          384
     383: iconst_0
     384: nop
     385: ifeq          337
     388: aload         8
     390: aload         11
     392: invokeinterface #203,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     397: pop
     398: goto          337
     401: aload         8
     403: checkcast     #38                 // class java/util/List
     406: nop
     407: checkcast     #28                 // class java/lang/Iterable
     410: astore        5
     412: nop
     413: iconst_0
     414: istore        6
     416: aload         5
     418: astore        7
     420: new           #183                // class java/util/ArrayList
     423: dup
     424: aload         5
     426: bipush        10
     428: invokestatic  #259                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     431: invokespecial #187                // Method java/util/ArrayList."<init>":(I)V
     434: checkcast     #189                // class java/util/Collection
     437: astore        8
     439: iconst_0
     440: istore        9
     442: aload         7
     444: invokeinterface #252,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     449: astore        10
     451: aload         10
     453: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     458: ifeq          505
     461: aload         10
     463: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     468: astore        11
     470: aload         8
     472: aload         11
     474: checkcast     #62                 // class java/lang/String
     477: astore        12
     479: astore        14
     481: iconst_0
     482: istore        13
     484: aload         12
     486: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     489: nop
     490: invokestatic  #128                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     493: aload         14
     495: swap
     496: invokeinterface #203,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     501: pop
     502: goto          451
     505: aload         8
     507: checkcast     #38                 // class java/util/List
     510: nop
     511: astore        4
     513: aload_3
     514: checkcast     #28                 // class java/lang/Iterable
     517: aload         4
     519: checkcast     #28                 // class java/lang/Iterable
     522: invokestatic  #263                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     525: checkcast     #28                 // class java/lang/Iterable
     528: invokestatic  #267                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     531: astore        5
     533: aload         5
     535: areturn
}

Compiled from "Scratchcard.kt"
public final class io.steinh.aoc.day04.ScratchcardKt {
  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 day04/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: new           #77                 // class io/steinh/aoc/day04/Scratchcard
      68: dup
      69: invokespecial #79                 // Method io/steinh/aoc/day04/Scratchcard."<init>":()V
      72: astore_1
      73: aload_1
      74: aload_0
      75: invokevirtual #83                 // Method io/steinh/aoc/day04/Scratchcard.calculatePoints:(Ljava/util/List;)I
      78: istore_2
      79: aload_1
      80: aload_0
      81: invokevirtual #86                 // Method io/steinh/aoc/day04/Scratchcard.calculateNumberOfCardsWon:(Ljava/util/List;)I
      84: istore_3
      85: new           #88                 // class java/lang/StringBuilder
      88: dup
      89: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
      92: ldc           #91                 // String Result day 04, part  I:
      94: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      97: iload_2
      98: invokevirtual #98                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     101: invokevirtual #102                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     104: getstatic     #108                // Field java/lang/System.out:Ljava/io/PrintStream;
     107: swap
     108: invokevirtual #113                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     111: new           #88                 // class java/lang/StringBuilder
     114: dup
     115: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
     118: ldc           #115                // String Result day 04, part II:
     120: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     123: iload_3
     124: invokevirtual #98                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     127: invokevirtual #102                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     130: getstatic     #108                // Field java/lang/System.out:Ljava/io/PrintStream;
     133: swap
     134: invokevirtual #113                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     137: return

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

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


package io.steinh.aoc.day03

class GearRatios {
    fun addUpPartNumbers(lines: List<String>): Int {

        var result = 0
        for (lineIndex in lines.indices) {
            val line = lines[lineIndex]

            val numberMatches = "(\\d+)".toRegex().findAll(line)

            for (numberMatch in numberMatches) {
                var startPos = numberMatch.groups[0]!!.range.first()
                if (startPos > 0) {
                    startPos -= 1
                }
                val endPos = numberMatch.groups[0]!!.range.last() + 1

                val startLineId = if (lineIndex > 0) lineIndex - 1 else 0
                val endLineId = if (lineIndex < lines.lastIndex) lineIndex + 1 else lineIndex

                if (hasAdjacentSymbol(lines, startLineId, endLineId, startPos, endPos)) {
                    result += numberMatch.groups[0]!!.value.toInt()
                }

            }

        }

        return result
    }

    fun calculateGearRatioSum(lines: List<String>): Int {
        var result = 0

        for (lineIndex in lines.indices) {
            val line = lines[lineIndex]

            val asteriskMatches = "([*])".toRegex().findAll(line)

            for (match in asteriskMatches) {
                result += searchAndCalculate(lines, lineIndex, match.groups[0]!!.range)
            }
        }

        return result
    }

    private fun searchAndCalculate(lines: List<String>, lineIndex: Int, range: IntRange): Int {
        val minLineId = if (lineIndex > 0) lineIndex - 1 else 0
        val maxLineId = if (lineIndex < lines.lastIndex) lineIndex + 1 else lineIndex

        val foundNumbers = mutableListOf<Int>()
        for (i in minLineId..maxLineId) {
            val line = lines[i]

            val numberMatches = "(\\d+)".toRegex().findAll(line)

            for (match in numberMatches) {
                val matchRange = match.groups[0]!!.range
                val startAt = if (matchRange.first() > 0) matchRange.first() - 1 else 0
                val endAt = matchRange.last() + 1

                if ((startAt..endAt).contains(range.first())) {
                    foundNumbers.add(match.groups[0]!!.value.toInt())
                }

            }
        }

        if (foundNumbers.size == 2) {
            return foundNumbers.first() * foundNumbers.last()
        }
        return 0
    }

    private fun hasAdjacentSymbol(
        lines: List<String>,
        startLineId: Int,
        endLineId: Int,
        startPos: Int,
        endPos: Int
    ): Boolean {
        var result = false
        for (i in startLineId..endLineId) {
            val max = if (endPos >= lines[i].length) lines[i].length - 1 else endPos
            val subString = lines[i].substring(startPos..max)

            result = result || subString.any { it != '.' && !it.isDigit() }
        }

        return result
    }
}

fun main() {
    val gearRatios = GearRatios()

    val lines = {}.javaClass.classLoader?.getResource("day03/input.txt")?.readText()?.lines()!!
    val resultPart1 = gearRatios.addUpPartNumbers(lines)
    val resultPart2 = gearRatios.calculateGearRatioSum(lines)

    print ("Result Day 3, Part  I: $resultPart1\n")
    print ("Result Day 3, Part II: $resultPart2\n")
}

Compiled from "GearRatios.kt"
public final class io.steinh.aoc.day03.GearRatiosKt {
  public static final void main();
    Code:
       0: new           #8                  // class io/steinh/aoc/day03/GearRatios
       3: dup
       4: invokespecial #11                 // Method io/steinh/aoc/day03/GearRatios."<init>":()V
       7: astore_0
       8: invokedynamic #30,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function0;
      13: invokevirtual #34                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      16: invokevirtual #40                 // Method java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader;
      19: dup
      20: ifnull        66
      23: ldc           #42                 // String day03/input.txt
      25: invokevirtual #48                 // Method java/lang/ClassLoader.getResource:(Ljava/lang/String;)Ljava/net/URL;
      28: dup
      29: ifnull        66
      32: astore        4
      34: getstatic     #54                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      37: astore        5
      39: aload         4
      41: invokestatic  #60                 // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      44: astore        6
      46: new           #62                 // class java/lang/String
      49: dup
      50: aload         6
      52: aload         5
      54: invokespecial #65                 // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      57: checkcast     #67                 // class java/lang/CharSequence
      60: invokestatic  #73                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      63: goto          68
      66: pop
      67: aconst_null
      68: dup
      69: invokestatic  #79                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      72: astore_1
      73: aload_0
      74: aload_1
      75: invokevirtual #83                 // Method io/steinh/aoc/day03/GearRatios.addUpPartNumbers:(Ljava/util/List;)I
      78: istore_2
      79: aload_0
      80: aload_1
      81: invokevirtual #86                 // Method io/steinh/aoc/day03/GearRatios.calculateGearRatioSum:(Ljava/util/List;)I
      84: istore_3
      85: new           #88                 // class java/lang/StringBuilder
      88: dup
      89: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
      92: ldc           #91                 // String Result Day 3, Part  I:
      94: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      97: iload_2
      98: invokevirtual #98                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     101: bipush        10
     103: invokevirtual #101                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     106: invokevirtual #105                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     109: getstatic     #111                // Field java/lang/System.out:Ljava/io/PrintStream;
     112: swap
     113: invokevirtual #116                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     116: new           #88                 // class java/lang/StringBuilder
     119: dup
     120: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
     123: ldc           #118                // String Result Day 3, Part II:
     125: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     128: iload_3
     129: invokevirtual #98                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     132: bipush        10
     134: invokevirtual #101                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     137: invokevirtual #105                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     140: getstatic     #111                // Field java/lang/System.out:Ljava/io/PrintStream;
     143: swap
     144: invokevirtual #116                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     147: return

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

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

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

  public final int addUpPartNumbers(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: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: aload_1
      11: checkcast     #24                 // class java/util/Collection
      14: invokeinterface #28,  1           // InterfaceMethod java/util/Collection.size:()I
      19: istore        4
      21: iload_3
      22: iload         4
      24: if_icmpge     239
      27: aload_1
      28: iload_3
      29: invokeinterface #34,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #36                 // class java/lang/String
      37: astore        5
      39: new           #38                 // class kotlin/text/Regex
      42: dup
      43: ldc           #40                 // String (\\d+)
      45: invokespecial #43                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      48: aload         5
      50: checkcast     #45                 // class java/lang/CharSequence
      53: iconst_0
      54: iconst_2
      55: aconst_null
      56: invokestatic  #49                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      59: astore        6
      61: aload         6
      63: invokeinterface #55,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      68: astore        7
      70: aload         7
      72: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          233
      80: aload         7
      82: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: checkcast     #67                 // class kotlin/text/MatchResult
      90: astore        8
      92: aload         8
      94: invokeinterface #71,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
      99: iconst_0
     100: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     105: dup
     106: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     109: invokevirtual #86                 // Method kotlin/text/MatchGroup.getRange:()Lkotlin/ranges/IntRange;
     112: checkcast     #88                 // class kotlin/ranges/IntProgression
     115: invokestatic  #94                 // Method kotlin/ranges/RangesKt.first:(Lkotlin/ranges/IntProgression;)I
     118: istore        9
     120: iload         9
     122: ifle          128
     125: iinc          9, -1
     128: aload         8
     130: invokeinterface #71,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     135: iconst_0
     136: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     141: dup
     142: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     145: invokevirtual #86                 // Method kotlin/text/MatchGroup.getRange:()Lkotlin/ranges/IntRange;
     148: checkcast     #88                 // class kotlin/ranges/IntProgression
     151: invokestatic  #97                 // Method kotlin/ranges/RangesKt.last:(Lkotlin/ranges/IntProgression;)I
     154: iconst_1
     155: iadd
     156: istore        10
     158: iload_3
     159: ifle          168
     162: iload_3
     163: iconst_1
     164: isub
     165: goto          169
     168: iconst_0
     169: istore        11
     171: iload_3
     172: aload_1
     173: invokestatic  #102                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     176: if_icmpge     185
     179: iload_3
     180: iconst_1
     181: iadd
     182: goto          186
     185: iload_3
     186: istore        12
     188: aload_0
     189: aload_1
     190: iload         11
     192: iload         12
     194: iload         9
     196: iload         10
     198: invokespecial #106                // Method hasAdjacentSymbol:(Ljava/util/List;IIII)Z
     201: ifeq          70
     204: iload_2
     205: aload         8
     207: invokeinterface #71,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     212: iconst_0
     213: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     218: dup
     219: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     222: invokevirtual #110                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     225: invokestatic  #116                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     228: iadd
     229: istore_2
     230: goto          70
     233: iinc          3, 1
     236: goto          21
     239: iload_2
     240: ireturn

  public final int calculateGearRatioSum(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: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: aload_1
      11: checkcast     #24                 // class java/util/Collection
      14: invokeinterface #28,  1           // InterfaceMethod java/util/Collection.size:()I
      19: istore        4
      21: iload_3
      22: iload         4
      24: if_icmpge     130
      27: aload_1
      28: iload_3
      29: invokeinterface #34,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #36                 // class java/lang/String
      37: astore        5
      39: new           #38                 // class kotlin/text/Regex
      42: dup
      43: ldc           #133                // String ([*])
      45: invokespecial #43                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      48: aload         5
      50: checkcast     #45                 // class java/lang/CharSequence
      53: iconst_0
      54: iconst_2
      55: aconst_null
      56: invokestatic  #49                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      59: astore        6
      61: aload         6
      63: invokeinterface #55,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      68: astore        7
      70: aload         7
      72: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          124
      80: aload         7
      82: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: checkcast     #67                 // class kotlin/text/MatchResult
      90: astore        8
      92: iload_2
      93: aload_0
      94: aload_1
      95: iload_3
      96: aload         8
      98: invokeinterface #71,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     103: iconst_0
     104: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     109: dup
     110: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     113: invokevirtual #86                 // Method kotlin/text/MatchGroup.getRange:()Lkotlin/ranges/IntRange;
     116: invokespecial #137                // Method searchAndCalculate:(Ljava/util/List;ILkotlin/ranges/IntRange;)I
     119: iadd
     120: istore_2
     121: goto          70
     124: iinc          3, 1
     127: goto          21
     130: iload_2
     131: ireturn

  private final int searchAndCalculate(java.util.List<java.lang.String>, int, kotlin.ranges.IntRange);
    Code:
       0: iload_2
       1: ifle          10
       4: iload_2
       5: iconst_1
       6: isub
       7: goto          11
      10: iconst_0
      11: istore        4
      13: iload_2
      14: aload_1
      15: invokestatic  #102                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      18: if_icmpge     27
      21: iload_2
      22: iconst_1
      23: iadd
      24: goto          28
      27: iload_2
      28: istore        5
      30: new           #142                // class java/util/ArrayList
      33: dup
      34: invokespecial #143                // Method java/util/ArrayList."<init>":()V
      37: checkcast     #30                 // class java/util/List
      40: astore        6
      42: iload         4
      44: istore        7
      46: iload         7
      48: iload         5
      50: if_icmpgt     254
      53: aload_1
      54: iload         7
      56: invokeinterface #34,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      61: checkcast     #36                 // class java/lang/String
      64: astore        8
      66: new           #38                 // class kotlin/text/Regex
      69: dup
      70: ldc           #40                 // String (\\d+)
      72: invokespecial #43                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      75: aload         8
      77: checkcast     #45                 // class java/lang/CharSequence
      80: iconst_0
      81: iconst_2
      82: aconst_null
      83: invokestatic  #49                 // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      86: astore        9
      88: aload         9
      90: invokeinterface #55,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      95: astore        10
      97: aload         10
      99: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     104: ifeq          241
     107: aload         10
     109: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     114: checkcast     #67                 // class kotlin/text/MatchResult
     117: astore        11
     119: aload         11
     121: invokeinterface #71,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     126: iconst_0
     127: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     132: dup
     133: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     136: invokevirtual #86                 // Method kotlin/text/MatchGroup.getRange:()Lkotlin/ranges/IntRange;
     139: astore        12
     141: aload         12
     143: checkcast     #88                 // class kotlin/ranges/IntProgression
     146: invokestatic  #94                 // Method kotlin/ranges/RangesKt.first:(Lkotlin/ranges/IntProgression;)I
     149: ifle          165
     152: aload         12
     154: checkcast     #88                 // class kotlin/ranges/IntProgression
     157: invokestatic  #94                 // Method kotlin/ranges/RangesKt.first:(Lkotlin/ranges/IntProgression;)I
     160: iconst_1
     161: isub
     162: goto          166
     165: iconst_0
     166: istore        13
     168: aload         12
     170: checkcast     #88                 // class kotlin/ranges/IntProgression
     173: invokestatic  #97                 // Method kotlin/ranges/RangesKt.last:(Lkotlin/ranges/IntProgression;)I
     176: iconst_1
     177: iadd
     178: istore        14
     180: new           #145                // class kotlin/ranges/IntRange
     183: dup
     184: iload         13
     186: iload         14
     188: invokespecial #148                // Method kotlin/ranges/IntRange."<init>":(II)V
     191: aload_3
     192: checkcast     #88                 // class kotlin/ranges/IntProgression
     195: invokestatic  #94                 // Method kotlin/ranges/RangesKt.first:(Lkotlin/ranges/IntProgression;)I
     198: invokevirtual #152                // Method kotlin/ranges/IntRange.contains:(I)Z
     201: ifeq          97
     204: aload         6
     206: aload         11
     208: invokeinterface #71,  1           // InterfaceMethod kotlin/text/MatchResult.getGroups:()Lkotlin/text/MatchGroupCollection;
     213: iconst_0
     214: invokeinterface #76,  2           // InterfaceMethod kotlin/text/MatchGroupCollection.get:(I)Lkotlin/text/MatchGroup;
     219: dup
     220: invokestatic  #80                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     223: invokevirtual #110                // Method kotlin/text/MatchGroup.getValue:()Ljava/lang/String;
     226: invokestatic  #116                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     229: invokestatic  #156                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     232: invokeinterface #160,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     237: pop
     238: goto          97
     241: iload         7
     243: iload         5
     245: if_icmpeq     254
     248: iinc          7, 1
     251: goto          53
     254: aload         6
     256: invokeinterface #161,  1          // InterfaceMethod java/util/List.size:()I
     261: iconst_2
     262: if_icmpne     289
     265: aload         6
     267: invokestatic  #164                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     270: checkcast     #166                // class java/lang/Number
     273: invokevirtual #169                // Method java/lang/Number.intValue:()I
     276: aload         6
     278: invokestatic  #171                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     281: checkcast     #166                // class java/lang/Number
     284: invokevirtual #169                // Method java/lang/Number.intValue:()I
     287: imul
     288: ireturn
     289: iconst_0
     290: ireturn

  private final boolean hasAdjacentSymbol(java.util.List<java.lang.String>, int, int, int, int);
    Code:
       0: iconst_0
       1: istore        6
       3: iload_2
       4: istore        7
       6: iload         7
       8: iload_3
       9: if_icmpgt     185
      12: iload         5
      14: aload_1
      15: iload         7
      17: invokeinterface #34,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: checkcast     #36                 // class java/lang/String
      25: invokevirtual #184                // Method java/lang/String.length:()I
      28: if_icmplt     50
      31: aload_1
      32: iload         7
      34: invokeinterface #34,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      39: checkcast     #36                 // class java/lang/String
      42: invokevirtual #184                // Method java/lang/String.length:()I
      45: iconst_1
      46: isub
      47: goto          52
      50: iload         5
      52: istore        8
      54: aload_1
      55: iload         7
      57: invokeinterface #34,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      62: checkcast     #36                 // class java/lang/String
      65: new           #145                // class kotlin/ranges/IntRange
      68: dup
      69: iload         4
      71: iload         8
      73: invokespecial #148                // Method kotlin/ranges/IntRange."<init>":(II)V
      76: invokestatic  #190                // Method kotlin/text/StringsKt.substring:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      79: astore        9
      81: iload         6
      83: ifne          166
      86: aload         9
      88: checkcast     #45                 // class java/lang/CharSequence
      91: astore        10
      93: iconst_0
      94: istore        11
      96: iconst_0
      97: istore        12
      99: iload         12
     101: aload         10
     103: invokeinterface #191,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     108: if_icmpge     162
     111: aload         10
     113: iload         12
     115: invokeinterface #195,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     120: istore        13
     122: iload         13
     124: istore        14
     126: iconst_0
     127: istore        15
     129: iload         14
     131: bipush        46
     133: if_icmpeq     148
     136: iload         14
     138: invokestatic  #201                // Method java/lang/Character.isDigit:(C)Z
     141: ifne          148
     144: iconst_1
     145: goto          149
     148: iconst_0
     149: ifeq          156
     152: iconst_1
     153: goto          163
     156: iinc          12, 1
     159: goto          99
     162: iconst_0
     163: ifeq          170
     166: iconst_1
     167: goto          171
     170: iconst_0
     171: istore        6
     173: iload         7
     175: iload_3
     176: if_icmpeq     185
     179: iinc          7, 1
     182: goto          12
     185: iload         6
     187: ireturn
}