import kotlin.String
import kotlin.collections.List

object Day1 {
    fun part1(input: List<String>): String = input.sumOf(::findFirstAndLastDigit).toString()

    private fun findFirstAndLastDigit(i: String): Int {
        val digits = i.filter { it.isDigit() }
        return (digits.take(1) + digits.takeLast(1)).toInt()
    }

    fun part2(input: List<String>): String = input.sumOf(::findFirstAndLastDigitV2).toString()

    private fun findFirstAndLastDigitV2(i: String): Int {
        val words = listOf("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine")
        val newI = words.zip(words.indices)
            .map { (word, index) -> word to word.first() + index.toString() + word.last() }
            .fold(i) { acc, (word, replacement) -> acc.replace(word, replacement) }
        return findFirstAndLastDigit(newI)
    }
}

Compiled from "Day1.kt"
public final class Day1 {
  public static final Day1 INSTANCE;

  private Day1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.lang.String part1(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore        4
      21: aload         4
      23: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      28: ifeq          70
      31: aload         4
      33: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: astore        5
      40: iload_3
      41: aload         5
      43: checkcast     #40                 // class java/lang/String
      46: astore        6
      48: istore        8
      50: iconst_0
      51: istore        7
      53: aload_0
      54: aload         6
      56: invokespecial #44                 // Method findFirstAndLastDigit:(Ljava/lang/String;)I
      59: istore        9
      61: iload         8
      63: iload         9
      65: iadd
      66: istore_3
      67: goto          21
      70: iload_3
      71: invokestatic  #48                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      74: areturn

  private final int findFirstAndLastDigit(java.lang.String);
    Code:
       0: aload_1
       1: astore_3
       2: iconst_0
       3: istore        4
       5: aload_3
       6: checkcast     #55                 // class java/lang/CharSequence
       9: astore        5
      11: new           #57                 // class java/lang/StringBuilder
      14: dup
      15: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
      18: checkcast     #60                 // class java/lang/Appendable
      21: astore        6
      23: iconst_0
      24: istore        7
      26: iconst_0
      27: istore        8
      29: aload         5
      31: invokeinterface #64,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      36: istore        9
      38: iload         8
      40: iload         9
      42: if_icmpge     88
      45: aload         5
      47: iload         8
      49: invokeinterface #68,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      54: istore        10
      56: iload         10
      58: istore        11
      60: iconst_0
      61: istore        12
      63: iload         11
      65: invokestatic  #74                 // Method java/lang/Character.isDigit:(C)Z
      68: nop
      69: ifeq          82
      72: aload         6
      74: iload         10
      76: invokeinterface #78,  2           // InterfaceMethod java/lang/Appendable.append:(C)Ljava/lang/Appendable;
      81: pop
      82: iinc          8, 1
      85: goto          38
      88: aload         6
      90: checkcast     #57                 // class java/lang/StringBuilder
      93: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: astore_2
      97: new           #57                 // class java/lang/StringBuilder
     100: dup
     101: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     104: aload_2
     105: iconst_1
     106: invokestatic  #88                 // Method kotlin/text/StringsKt.take:(Ljava/lang/String;I)Ljava/lang/String;
     109: invokevirtual #91                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     112: aload_2
     113: iconst_1
     114: invokestatic  #94                 // Method kotlin/text/StringsKt.takeLast:(Ljava/lang/String;I)Ljava/lang/String;
     117: invokevirtual #91                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     120: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     123: invokestatic  #99                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     126: ireturn

  public final java.lang.String part2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String input
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #24                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore        4
      21: aload         4
      23: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      28: ifeq          70
      31: aload         4
      33: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: astore        5
      40: iload_3
      41: aload         5
      43: checkcast     #40                 // class java/lang/String
      46: astore        6
      48: istore        8
      50: iconst_0
      51: istore        7
      53: aload_0
      54: aload         6
      56: invokespecial #117                // Method findFirstAndLastDigitV2:(Ljava/lang/String;)I
      59: istore        9
      61: iload         8
      63: iload         9
      65: iadd
      66: istore_3
      67: goto          21
      70: iload_3
      71: invokestatic  #48                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      74: areturn

  private final int findFirstAndLastDigitV2(java.lang.String);
    Code:
       0: bipush        10
       2: anewarray     #40                 // class java/lang/String
       5: astore_3
       6: aload_3
       7: iconst_0
       8: ldc           #120                // String zero
      10: aastore
      11: aload_3
      12: iconst_1
      13: ldc           #122                // String one
      15: aastore
      16: aload_3
      17: iconst_2
      18: ldc           #124                // String two
      20: aastore
      21: aload_3
      22: iconst_3
      23: ldc           #126                // String three
      25: aastore
      26: aload_3
      27: iconst_4
      28: ldc           #128                // String four
      30: aastore
      31: aload_3
      32: iconst_5
      33: ldc           #130                // String five
      35: aastore
      36: aload_3
      37: bipush        6
      39: ldc           #132                // String six
      41: aastore
      42: aload_3
      43: bipush        7
      45: ldc           #134                // String seven
      47: aastore
      48: aload_3
      49: bipush        8
      51: ldc           #136                // String eight
      53: aastore
      54: aload_3
      55: bipush        9
      57: ldc           #138                // String nine
      59: aastore
      60: aload_3
      61: invokestatic  #144                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      64: astore_2
      65: aload_2
      66: checkcast     #24                 // class java/lang/Iterable
      69: aload_2
      70: checkcast     #146                // class java/util/Collection
      73: invokestatic  #150                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      76: checkcast     #24                 // class java/lang/Iterable
      79: invokestatic  #154                // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
      82: checkcast     #24                 // class java/lang/Iterable
      85: astore        4
      87: nop
      88: iconst_0
      89: istore        5
      91: aload         4
      93: astore        6
      95: new           #156                // class java/util/ArrayList
      98: dup
      99: aload         4
     101: bipush        10
     103: invokestatic  #160                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     106: invokespecial #163                // Method java/util/ArrayList."<init>":(I)V
     109: checkcast     #146                // class java/util/Collection
     112: astore        7
     114: iconst_0
     115: istore        8
     117: aload         6
     119: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     124: astore        9
     126: aload         9
     128: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     133: ifeq          260
     136: aload         9
     138: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     143: astore        10
     145: aload         7
     147: aload         10
     149: checkcast     #165                // class kotlin/Pair
     152: astore        11
     154: astore        17
     156: iconst_0
     157: istore        12
     159: aload         11
     161: invokevirtual #168                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     164: checkcast     #40                 // class java/lang/String
     167: astore        13
     169: aload         11
     171: invokevirtual #171                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     174: checkcast     #173                // class java/lang/Number
     177: invokevirtual #176                // Method java/lang/Number.intValue:()I
     180: istore        14
     182: aload         13
     184: new           #57                 // class java/lang/StringBuilder
     187: dup
     188: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     191: aload         13
     193: checkcast     #55                 // class java/lang/CharSequence
     196: invokestatic  #180                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     199: istore        15
     201: iload         14
     203: invokestatic  #48                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
     206: astore        16
     208: new           #57                 // class java/lang/StringBuilder
     211: dup
     212: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     215: iload         15
     217: invokevirtual #183                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     220: aload         16
     222: invokevirtual #91                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     225: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     228: invokevirtual #91                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     231: aload         13
     233: checkcast     #55                 // class java/lang/CharSequence
     236: invokestatic  #186                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     239: invokevirtual #183                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     242: invokevirtual #82                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     245: invokestatic  #192                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     248: aload         17
     250: swap
     251: invokeinterface #196,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     256: pop
     257: goto          126
     260: aload         7
     262: checkcast     #198                // class java/util/List
     265: nop
     266: checkcast     #24                 // class java/lang/Iterable
     269: astore        4
     271: nop
     272: iconst_0
     273: istore        5
     275: aload_1
     276: astore        6
     278: aload         4
     280: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     285: astore        7
     287: aload         7
     289: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     294: ifeq          357
     297: aload         7
     299: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     304: astore        8
     306: aload         6
     308: aload         8
     310: checkcast     #165                // class kotlin/Pair
     313: astore        9
     315: astore        10
     317: iconst_0
     318: istore        11
     320: aload         9
     322: invokevirtual #168                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     325: checkcast     #40                 // class java/lang/String
     328: astore        12
     330: aload         9
     332: invokevirtual #171                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     335: checkcast     #40                 // class java/lang/String
     338: astore        13
     340: aload         10
     342: aload         12
     344: aload         13
     346: iconst_0
     347: iconst_4
     348: aconst_null
     349: invokestatic  #202                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
     352: astore        6
     354: goto          287
     357: aload         6
     359: astore_3
     360: aload_0
     361: aload_3
     362: invokespecial #44                 // Method findFirstAndLastDigit:(Ljava/lang/String;)I
     365: ireturn

  static {};
    Code:
       0: new           #2                  // class Day1
       3: dup
       4: invokespecial #226                // Method "<init>":()V
       7: putstatic     #229                // Field INSTANCE:LDay1;
      10: return
}