package com.shifteleven.adventofcode2023.day01

import kotlin.math.min

fun main() {
	part1()
	part2()
}

fun part1() {
	val lines = object {}.javaClass.getResourceAsStream("/input.txt")!!.bufferedReader().readLines()
	val sum =
		lines
			.stream()
			.mapToInt({ line ->
				var tens: Int? = null
				var ones = 0
				for (c in line) {
					when (c) {
						in CharRange('0', '9') -> {
							ones = c.code - 0x30
							tens = tens ?: ones * 10
						}
					}
				}
				tens!! + ones
			})
			.sum()
	println("Part 1: " + sum)
}

fun part2() {
	val lines = object {}.javaClass.getResourceAsStream("/input.txt")!!.bufferedReader().readLines()
	val sum =
		lines
			.stream()
			.mapToInt({ line ->
				var tens: Int? = null
				var ones = 0
				for ((i, c) in line.withIndex()) {
					var num: Int? = null
					when (c) {
						in CharRange('0', '9') -> {
							num = c.code - 0x30
						}
						'o' -> {
							if (matchesWord(line, i, "one")) {
								num = 1
							}
						}
						't' -> {
							if (matchesWord(line, i, "two")) {
								num = 2
							} else if (matchesWord(line, i, "three")) {
								num = 3
							}
						}
						'f' -> {
							if (matchesWord(line, i, "four")) {
								num = 4
							} else if (matchesWord(line, i, "five")) {
								num = 5
							}
						}
						's' -> {
							if (matchesWord(line, i, "six")) {
								num = 6
							} else if (matchesWord(line, i, "seven")) {
								num = 7
							}
						}
						'e' -> {
							if (matchesWord(line, i, "eight")) {
								num = 8
							}
						}
						'n' -> {
							if (matchesWord(line, i, "nine")) {
								num = 9
							}
						}
					}
					if (num != null) {
						ones = num
						tens = tens ?: num * 10
					}
				}
				tens!! + ones
			})
			.sum()
	println("Part 2: " + sum)
}

fun matchesWord(
	line: String,
	idx: Int,
	word: String,
): Boolean {
	return line.subSequence(idx, min(idx + word.length, line.length)) == word
}

Compiled from "App.kt"
public final class com.shifteleven.adventofcode2023.day01.AppKt {
  public static final void main();
    Code:
       0: invokestatic  #9                  // Method part1:()V
       3: invokestatic  #12                 // Method part2:()V
       6: return

  public static final void part1();
    Code:
       0: new           #14                 // class com/shifteleven/adventofcode2023/day01/AppKt$part1$lines$1
       3: dup
       4: invokespecial #17                 // Method com/shifteleven/adventofcode2023/day01/AppKt$part1$lines$1."<init>":()V
       7: invokevirtual #21                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      10: ldc           #23                 // String /input.txt
      12: invokevirtual #29                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      15: dup
      16: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      19: astore_1
      20: getstatic     #41                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      23: astore_2
      24: new           #43                 // class java/io/InputStreamReader
      27: dup
      28: aload_1
      29: aload_2
      30: invokespecial #46                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      33: checkcast     #48                 // class java/io/Reader
      36: astore_3
      37: sipush        8192
      40: istore        4
      42: aload_3
      43: instanceof    #50                 // class java/io/BufferedReader
      46: ifeq          56
      49: aload_3
      50: checkcast     #50                 // class java/io/BufferedReader
      53: goto          66
      56: new           #50                 // class java/io/BufferedReader
      59: dup
      60: aload_3
      61: iload         4
      63: invokespecial #53                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      66: checkcast     #48                 // class java/io/Reader
      69: invokestatic  #59                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      72: astore_0
      73: aload_0
      74: invokeinterface #65,  1           // InterfaceMethod java/util/List.stream:()Ljava/util/stream/Stream;
      79: invokedynamic #85,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      84: invokedynamic #96,  0             // InvokeDynamic #1:applyAsInt:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/ToIntFunction;
      89: invokeinterface #102,  2          // InterfaceMethod java/util/stream/Stream.mapToInt:(Ljava/util/function/ToIntFunction;)Ljava/util/stream/IntStream;
      94: invokeinterface #108,  1          // InterfaceMethod java/util/stream/IntStream.sum:()I
      99: istore_1
     100: new           #110                // class java/lang/StringBuilder
     103: dup
     104: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
     107: ldc           #113                // String Part 1:
     109: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     112: iload_1
     113: invokevirtual #120                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     116: invokevirtual #124                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     119: getstatic     #130                // Field java/lang/System.out:Ljava/io/PrintStream;
     122: swap
     123: invokevirtual #135                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     126: return

  public static final void part2();
    Code:
       0: new           #144                // class com/shifteleven/adventofcode2023/day01/AppKt$part2$lines$1
       3: dup
       4: invokespecial #145                // Method com/shifteleven/adventofcode2023/day01/AppKt$part2$lines$1."<init>":()V
       7: invokevirtual #21                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      10: ldc           #23                 // String /input.txt
      12: invokevirtual #29                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      15: dup
      16: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      19: astore_1
      20: getstatic     #41                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      23: astore_2
      24: new           #43                 // class java/io/InputStreamReader
      27: dup
      28: aload_1
      29: aload_2
      30: invokespecial #46                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      33: checkcast     #48                 // class java/io/Reader
      36: astore_3
      37: sipush        8192
      40: istore        4
      42: aload_3
      43: instanceof    #50                 // class java/io/BufferedReader
      46: ifeq          56
      49: aload_3
      50: checkcast     #50                 // class java/io/BufferedReader
      53: goto          66
      56: new           #50                 // class java/io/BufferedReader
      59: dup
      60: aload_3
      61: iload         4
      63: invokespecial #53                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      66: checkcast     #48                 // class java/io/Reader
      69: invokestatic  #59                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      72: astore_0
      73: aload_0
      74: invokeinterface #65,  1           // InterfaceMethod java/util/List.stream:()Ljava/util/stream/Stream;
      79: invokedynamic #150,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
      84: invokedynamic #155,  0            // InvokeDynamic #3:applyAsInt:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/ToIntFunction;
      89: invokeinterface #102,  2          // InterfaceMethod java/util/stream/Stream.mapToInt:(Ljava/util/function/ToIntFunction;)Ljava/util/stream/IntStream;
      94: invokeinterface #108,  1          // InterfaceMethod java/util/stream/IntStream.sum:()I
      99: istore_1
     100: new           #110                // class java/lang/StringBuilder
     103: dup
     104: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
     107: ldc           #157                // String Part 2:
     109: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     112: iload_1
     113: invokevirtual #120                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     116: invokevirtual #124                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     119: getstatic     #130                // Field java/lang/System.out:Ljava/io/PrintStream;
     122: swap
     123: invokevirtual #135                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     126: return

  public static final boolean matchesWord(java.lang.String, int, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #162                // String line
       3: invokestatic  #166                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #168                // String word
       9: invokestatic  #166                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iload_1
      14: iload_1
      15: aload_2
      16: invokevirtual #173                // Method java/lang/String.length:()I
      19: iadd
      20: aload_0
      21: invokevirtual #173                // Method java/lang/String.length:()I
      24: invokestatic  #179                // Method java/lang/Math.min:(II)I
      27: invokevirtual #183                // Method java/lang/String.subSequence:(II)Ljava/lang/CharSequence;
      30: aload_2
      31: invokestatic  #187                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      34: ireturn

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

  private static final int part1$lambda$0(java.lang.String);
    Code:
       0: aconst_null
       1: astore_1
       2: iconst_0
       3: istore_2
       4: aload_0
       5: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       8: aload_0
       9: astore_3
      10: iconst_0
      11: istore        4
      13: aload_3
      14: invokevirtual #173                // Method java/lang/String.length:()I
      17: istore        5
      19: iload         4
      21: iload         5
      23: if_icmpge     113
      26: aload_3
      27: iload         4
      29: invokevirtual #198                // Method java/lang/String.charAt:(I)C
      32: istore        6
      34: iload         6
      36: istore        7
      38: new           #200                // class kotlin/ranges/CharRange
      41: dup
      42: bipush        48
      44: bipush        57
      46: invokespecial #203                // Method kotlin/ranges/CharRange."<init>":(CC)V
      49: astore        8
      51: aload         8
      53: invokevirtual #207                // Method kotlin/ranges/CharRange.getFirst:()C
      56: istore        9
      58: iload         7
      60: aload         8
      62: invokevirtual #210                // Method kotlin/ranges/CharRange.getLast:()C
      65: if_icmpgt     83
      68: iload         9
      70: iload         7
      72: if_icmpgt     79
      75: iconst_1
      76: goto          84
      79: iconst_0
      80: goto          84
      83: iconst_0
      84: ifeq          107
      87: iload         6
      89: bipush        48
      91: isub
      92: istore_2
      93: aload_1
      94: dup
      95: ifnonnull     106
      98: pop
      99: iload_2
     100: bipush        10
     102: imul
     103: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: astore_1
     107: iinc          4, 1
     110: goto          19
     113: aload_1
     114: dup
     115: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     118: invokevirtual #219                // Method java/lang/Integer.intValue:()I
     121: iload_2
     122: iadd
     123: ireturn

  private static final int part1$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #228,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #230                // class java/lang/Number
      10: invokevirtual #231                // Method java/lang/Number.intValue:()I
      13: ireturn

  private static final int part2$lambda$2(java.lang.String);
    Code:
       0: aconst_null
       1: astore_1
       2: iconst_0
       3: istore_2
       4: aload_0
       5: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       8: aload_0
       9: astore_3
      10: iconst_0
      11: istore        4
      13: aload_3
      14: invokevirtual #173                // Method java/lang/String.length:()I
      17: istore        5
      19: iload         4
      21: iload         5
      23: if_icmpge     365
      26: iload         4
      28: istore        6
      30: aload_3
      31: iload         4
      33: invokevirtual #198                // Method java/lang/String.charAt:(I)C
      36: istore        7
      38: aconst_null
      39: astore        8
      41: iload         7
      43: istore        9
      45: new           #200                // class kotlin/ranges/CharRange
      48: dup
      49: bipush        48
      51: bipush        57
      53: invokespecial #203                // Method kotlin/ranges/CharRange."<init>":(CC)V
      56: astore        10
      58: aload         10
      60: invokevirtual #207                // Method kotlin/ranges/CharRange.getFirst:()C
      63: istore        11
      65: iload         9
      67: aload         10
      69: invokevirtual #210                // Method kotlin/ranges/CharRange.getLast:()C
      72: if_icmpgt     90
      75: iload         11
      77: iload         9
      79: if_icmpgt     86
      82: iconst_1
      83: goto          91
      86: iconst_0
      87: goto          91
      90: iconst_0
      91: ifeq          107
      94: iload         7
      96: bipush        48
      98: isub
      99: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: astore        8
     104: goto          330
     107: iload         9
     109: bipush        111
     111: if_icmpne     134
     114: aload_0
     115: iload         6
     117: ldc           #237                // String one
     119: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     122: ifeq          330
     125: iconst_1
     126: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     129: astore        8
     131: goto          330
     134: iload         9
     136: bipush        116
     138: if_icmpne     181
     141: aload_0
     142: iload         6
     144: ldc           #241                // String two
     146: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     149: ifeq          161
     152: iconst_2
     153: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     156: astore        8
     158: goto          330
     161: aload_0
     162: iload         6
     164: ldc           #243                // String three
     166: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     169: ifeq          330
     172: iconst_3
     173: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     176: astore        8
     178: goto          330
     181: iload         9
     183: bipush        102
     185: if_icmpne     228
     188: aload_0
     189: iload         6
     191: ldc           #245                // String four
     193: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     196: ifeq          208
     199: iconst_4
     200: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     203: astore        8
     205: goto          330
     208: aload_0
     209: iload         6
     211: ldc           #247                // String five
     213: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     216: ifeq          330
     219: iconst_5
     220: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     223: astore        8
     225: goto          330
     228: iload         9
     230: bipush        115
     232: if_icmpne     277
     235: aload_0
     236: iload         6
     238: ldc           #249                // String six
     240: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     243: ifeq          256
     246: bipush        6
     248: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     251: astore        8
     253: goto          330
     256: aload_0
     257: iload         6
     259: ldc           #251                // String seven
     261: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     264: ifeq          330
     267: bipush        7
     269: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     272: astore        8
     274: goto          330
     277: iload         9
     279: bipush        101
     281: if_icmpne     305
     284: aload_0
     285: iload         6
     287: ldc           #253                // String eight
     289: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     292: ifeq          330
     295: bipush        8
     297: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     300: astore        8
     302: goto          330
     305: iload         9
     307: bipush        110
     309: if_icmpne     330
     312: aload_0
     313: iload         6
     315: ldc           #255                // String nine
     317: invokestatic  #239                // Method matchesWord:(Ljava/lang/String;ILjava/lang/String;)Z
     320: ifeq          330
     323: bipush        9
     325: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     328: astore        8
     330: aload         8
     332: ifnull        359
     335: aload         8
     337: invokevirtual #219                // Method java/lang/Integer.intValue:()I
     340: istore_2
     341: aload_1
     342: dup
     343: ifnonnull     358
     346: pop
     347: aload         8
     349: invokevirtual #219                // Method java/lang/Integer.intValue:()I
     352: bipush        10
     354: imul
     355: invokestatic  #216                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     358: astore_1
     359: iinc          4, 1
     362: goto          19
     365: aload_1
     366: dup
     367: invokestatic  #35                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     370: invokevirtual #219                // Method java/lang/Integer.intValue:()I
     373: iload_2
     374: iadd
     375: ireturn

  private static final int part2$lambda$3(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #228,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #230                // class java/lang/Number
      10: invokevirtual #231                // Method java/lang/Number.intValue:()I
      13: ireturn
}

Compiled from "App.kt"
public final class com.shifteleven.adventofcode2023.day01.AppKt$part2$lines$1 {
  com.shifteleven.adventofcode2023.day01.AppKt$part2$lines$1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return
}

Compiled from "App.kt"
public final class com.shifteleven.adventofcode2023.day01.AppKt$part1$lines$1 {
  com.shifteleven.adventofcode2023.day01.AppKt$part1$lines$1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return
}


package com.shifteleven.adventofcode2023.day02

import java.io.StreamTokenizer
import java.io.StringReader
import kotlin.assert
import kotlin.math.max

data class Game(val id: Int, val views: List<IntArray>)

fun main() {
	val lines = object {}.javaClass.getResourceAsStream("/input.txt")!!.bufferedReader().readLines()
	val games = lines.map { processLine(it) }
	part1(games)
	part2(games)
}

fun part1(games: List<Game>) {
	val sum =
		games
			.filter { game -> game.views.all { it[0] <= 12 && it[1] <= 13 && it[2] <= 14 } }
			.map { it.id }
			.sum()
	println("Part 1: " + sum)
}

fun part2(games: List<Game>) {
	val sum =
		games
			.map { game ->
				var r = 1
				var g = 1
				var b = 1
				for (dice in game.views) {
					r = max(dice[0], r)
					g = max(dice[1], g)
					b = max(dice[2], b)
				}
				r * g * b
			}
			.sum()
	println("Part 2: " + sum)
}

fun processLine(line: String): Game {
	val r = StringReader(line)
	val t = StreamTokenizer(r)

	t.nextToken()
	assert(t.sval == "Game")

	t.nextToken()
	assert(t.ttype == StreamTokenizer.TT_NUMBER)
	val gameId = t.nval.toInt()

	val cur = t.nextToken() // :
	assert(cur.toChar() == ':')

	val views = mutableListOf<IntArray>()

	do {
		val dice = IntArray(3)
		do {
			t.nextToken()
			assert(t.ttype == StreamTokenizer.TT_NUMBER)
			val curColor = t.nval.toInt()
			t.nextToken()
			assert(t.ttype == StreamTokenizer.TT_WORD)
			when (t.sval) {
				"red" -> dice[0] = curColor
				"green" -> dice[1] = curColor
				"blue" -> dice[2] = curColor
				else -> assert(false)
			}
		} while (isRgbGroupActive(t))

		views.add(dice)
	} while (isGameContinued(t))

	assert(t.nextToken() == StreamTokenizer.TT_EOF)

	return Game(gameId, views)
}

fun isRgbGroupActive(t: StreamTokenizer): Boolean {
	val tok = t.nextToken()
	if (tok.toChar() == ',') {
		return true
	}
	t.pushBack()
	return false
}

fun isGameContinued(t: StreamTokenizer): Boolean {
	val tok = t.nextToken()
	if (tok.toChar() == ';') {
		return true
	}
	t.pushBack()
	return false
}

Compiled from "App.kt"
public final class com.shifteleven.adventofcode2023.day02.AppKt {
  public static final void main();
    Code:
       0: new           #8                  // class com/shifteleven/adventofcode2023/day02/AppKt$main$lines$1
       3: dup
       4: invokespecial #11                 // Method com/shifteleven/adventofcode2023/day02/AppKt$main$lines$1."<init>":()V
       7: invokevirtual #15                 // Method java/lang/Object.getClass:()Ljava/lang/Class;
      10: ldc           #17                 // String /input.txt
      12: invokevirtual #23                 // Method java/lang/Class.getResourceAsStream:(Ljava/lang/String;)Ljava/io/InputStream;
      15: dup
      16: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      19: astore_1
      20: getstatic     #35                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      23: astore_2
      24: new           #37                 // class java/io/InputStreamReader
      27: dup
      28: aload_1
      29: aload_2
      30: invokespecial #40                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      33: checkcast     #42                 // class java/io/Reader
      36: astore_3
      37: sipush        8192
      40: istore        4
      42: aload_3
      43: instanceof    #44                 // class java/io/BufferedReader
      46: ifeq          56
      49: aload_3
      50: checkcast     #44                 // class java/io/BufferedReader
      53: goto          66
      56: new           #44                 // class java/io/BufferedReader
      59: dup
      60: aload_3
      61: iload         4
      63: invokespecial #47                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      66: checkcast     #42                 // class java/io/Reader
      69: invokestatic  #53                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      72: astore_0
      73: aload_0
      74: checkcast     #55                 // class java/lang/Iterable
      77: astore_2
      78: iconst_0
      79: istore_3
      80: aload_2
      81: astore        4
      83: new           #57                 // class java/util/ArrayList
      86: dup
      87: aload_2
      88: bipush        10
      90: invokestatic  #63                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      93: invokespecial #66                 // Method java/util/ArrayList."<init>":(I)V
      96: checkcast     #68                 // class java/util/Collection
      99: astore        5
     101: iconst_0
     102: istore        6
     104: aload         4
     106: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     111: astore        7
     113: aload         7
     115: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     120: ifeq          163
     123: aload         7
     125: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     130: astore        8
     132: aload         5
     134: aload         8
     136: checkcast     #84                 // class java/lang/String
     139: astore        9
     141: astore        11
     143: iconst_0
     144: istore        10
     146: aload         9
     148: invokestatic  #88                 // Method processLine:(Ljava/lang/String;)Lcom/shifteleven/adventofcode2023/day02/Game;
     151: aload         11
     153: swap
     154: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     159: pop
     160: goto          113
     163: aload         5
     165: checkcast     #94                 // class java/util/List
     168: nop
     169: astore_1
     170: aload_1
     171: invokestatic  #98                 // Method part1:(Ljava/util/List;)V
     174: aload_1
     175: invokestatic  #101                // Method part2:(Ljava/util/List;)V
     178: return

  public static final void part1(java.util.List<com.shifteleven.adventofcode2023.day02.Game>);
    Code:
       0: aload_0
       1: ldc           #124                // String games
       3: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #55                 // class java/lang/Iterable
      10: astore_2
      11: nop
      12: iconst_0
      13: istore_3
      14: aload_2
      15: astore        4
      17: new           #57                 // class java/util/ArrayList
      20: dup
      21: invokespecial #129                // Method java/util/ArrayList."<init>":()V
      24: checkcast     #68                 // class java/util/Collection
      27: astore        5
      29: iconst_0
      30: istore        6
      32: aload         4
      34: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        7
      41: aload         7
      43: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          203
      51: aload         7
      53: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        8
      60: aload         8
      62: checkcast     #131                // class com/shifteleven/adventofcode2023/day02/Game
      65: astore        9
      67: iconst_0
      68: istore        10
      70: aload         9
      72: invokevirtual #135                // Method com/shifteleven/adventofcode2023/day02/Game.getViews:()Ljava/util/List;
      75: checkcast     #55                 // class java/lang/Iterable
      78: astore        11
      80: iconst_0
      81: istore        12
      83: aload         11
      85: instanceof    #68                 // class java/util/Collection
      88: ifeq          108
      91: aload         11
      93: checkcast     #68                 // class java/util/Collection
      96: invokeinterface #138,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     101: ifeq          108
     104: iconst_1
     105: goto          186
     108: aload         11
     110: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     115: astore        13
     117: aload         13
     119: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     124: ifeq          185
     127: aload         13
     129: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     134: astore        14
     136: aload         14
     138: checkcast     #140                // class "[I"
     141: astore        15
     143: iconst_0
     144: istore        16
     146: aload         15
     148: iconst_0
     149: iaload
     150: bipush        12
     152: if_icmpgt     177
     155: aload         15
     157: iconst_1
     158: iaload
     159: bipush        13
     161: if_icmpgt     177
     164: aload         15
     166: iconst_2
     167: iaload
     168: bipush        14
     170: if_icmpgt     177
     173: iconst_1
     174: goto          178
     177: iconst_0
     178: ifne          117
     181: iconst_0
     182: goto          186
     185: iconst_1
     186: nop
     187: ifeq          41
     190: aload         5
     192: aload         8
     194: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     199: pop
     200: goto          41
     203: aload         5
     205: checkcast     #94                 // class java/util/List
     208: nop
     209: checkcast     #55                 // class java/lang/Iterable
     212: astore_2
     213: nop
     214: iconst_0
     215: istore_3
     216: aload_2
     217: astore        4
     219: new           #57                 // class java/util/ArrayList
     222: dup
     223: aload_2
     224: bipush        10
     226: invokestatic  #63                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     229: invokespecial #66                 // Method java/util/ArrayList."<init>":(I)V
     232: checkcast     #68                 // class java/util/Collection
     235: astore        5
     237: iconst_0
     238: istore        6
     240: aload         4
     242: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     247: astore        7
     249: aload         7
     251: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     256: ifeq          302
     259: aload         7
     261: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     266: astore        8
     268: aload         5
     270: aload         8
     272: checkcast     #131                // class com/shifteleven/adventofcode2023/day02/Game
     275: astore        9
     277: astore        17
     279: iconst_0
     280: istore        10
     282: aload         9
     284: invokevirtual #144                // Method com/shifteleven/adventofcode2023/day02/Game.getId:()I
     287: invokestatic  #150                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     290: aload         17
     292: swap
     293: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     298: pop
     299: goto          249
     302: aload         5
     304: checkcast     #94                 // class java/util/List
     307: nop
     308: checkcast     #55                 // class java/lang/Iterable
     311: invokestatic  #154                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     314: istore_1
     315: new           #156                // class java/lang/StringBuilder
     318: dup
     319: invokespecial #157                // Method java/lang/StringBuilder."<init>":()V
     322: ldc           #159                // String Part 1:
     324: invokevirtual #163                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     327: iload_1
     328: invokevirtual #166                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     331: invokevirtual #170                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     334: getstatic     #176                // Field java/lang/System.out:Ljava/io/PrintStream;
     337: swap
     338: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     341: return

  public static final void part2(java.util.List<com.shifteleven.adventofcode2023.day02.Game>);
    Code:
       0: aload_0
       1: ldc           #124                // String games
       3: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #55                 // class java/lang/Iterable
      10: astore_2
      11: nop
      12: iconst_0
      13: istore_3
      14: aload_2
      15: astore        4
      17: new           #57                 // class java/util/ArrayList
      20: dup
      21: aload_2
      22: bipush        10
      24: invokestatic  #63                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #66                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #68                 // class java/util/Collection
      33: astore        5
      35: iconst_0
      36: istore        6
      38: aload         4
      40: invokeinterface #72,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        7
      47: aload         7
      49: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          182
      57: aload         7
      59: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        8
      66: aload         5
      68: aload         8
      70: checkcast     #131                // class com/shifteleven/adventofcode2023/day02/Game
      73: astore        9
      75: astore        16
      77: iconst_0
      78: istore        10
      80: iconst_1
      81: istore        11
      83: iconst_1
      84: istore        12
      86: iconst_1
      87: istore        13
      89: aload         9
      91: invokevirtual #135                // Method com/shifteleven/adventofcode2023/day02/Game.getViews:()Ljava/util/List;
      94: invokeinterface #196,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      99: astore        14
     101: aload         14
     103: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     108: ifeq          159
     111: aload         14
     113: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     118: checkcast     #140                // class "[I"
     121: astore        15
     123: aload         15
     125: iconst_0
     126: iaload
     127: iload         11
     129: invokestatic  #202                // Method java/lang/Math.max:(II)I
     132: istore        11
     134: aload         15
     136: iconst_1
     137: iaload
     138: iload         12
     140: invokestatic  #202                // Method java/lang/Math.max:(II)I
     143: istore        12
     145: aload         15
     147: iconst_2
     148: iaload
     149: iload         13
     151: invokestatic  #202                // Method java/lang/Math.max:(II)I
     154: istore        13
     156: goto          101
     159: iload         11
     161: iload         12
     163: imul
     164: iload         13
     166: imul
     167: invokestatic  #150                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     170: aload         16
     172: swap
     173: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     178: pop
     179: goto          47
     182: aload         5
     184: checkcast     #94                 // class java/util/List
     187: nop
     188: checkcast     #55                 // class java/lang/Iterable
     191: invokestatic  #154                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     194: istore_1
     195: new           #156                // class java/lang/StringBuilder
     198: dup
     199: invokespecial #157                // Method java/lang/StringBuilder."<init>":()V
     202: ldc           #204                // String Part 2:
     204: invokevirtual #163                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     207: iload_1
     208: invokevirtual #166                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     211: invokevirtual #170                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     214: getstatic     #176                // Field java/lang/System.out:Ljava/io/PrintStream;
     217: swap
     218: invokevirtual #181                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     221: return

  public static final com.shifteleven.adventofcode2023.day02.Game processLine(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #211                // String line
       3: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #213                // class java/io/StringReader
       9: dup
      10: aload_0
      11: invokespecial #216                // Method java/io/StringReader."<init>":(Ljava/lang/String;)V
      14: astore_1
      15: new           #218                // class java/io/StreamTokenizer
      18: dup
      19: aload_1
      20: checkcast     #42                 // class java/io/Reader
      23: invokespecial #221                // Method java/io/StreamTokenizer."<init>":(Ljava/io/Reader;)V
      26: astore_2
      27: aload_2
      28: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
      31: pop
      32: aload_2
      33: getfield      #227                // Field java/io/StreamTokenizer.sval:Ljava/lang/String;
      36: ldc           #229                // String Game
      38: invokestatic  #233                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      41: istore_3
      42: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
      45: ifeq          66
      48: iload_3
      49: ifne          66
      52: ldc           #241                // String Assertion failed
      54: astore        4
      56: new           #243                // class java/lang/AssertionError
      59: dup
      60: aload         4
      62: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      65: athrow
      66: aload_2
      67: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
      70: pop
      71: aload_2
      72: getfield      #248                // Field java/io/StreamTokenizer.ttype:I
      75: bipush        -2
      77: if_icmpne     84
      80: iconst_1
      81: goto          85
      84: iconst_0
      85: istore_3
      86: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
      89: ifeq          110
      92: iload_3
      93: ifne          110
      96: ldc           #241                // String Assertion failed
      98: astore        4
     100: new           #243                // class java/lang/AssertionError
     103: dup
     104: aload         4
     106: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     109: athrow
     110: aload_2
     111: getfield      #252                // Field java/io/StreamTokenizer.nval:D
     114: d2i
     115: istore_3
     116: aload_2
     117: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
     120: istore        4
     122: iload         4
     124: i2c
     125: bipush        58
     127: if_icmpne     134
     130: iconst_1
     131: goto          135
     134: iconst_0
     135: istore        5
     137: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
     140: ifeq          162
     143: iload         5
     145: ifne          162
     148: ldc           #241                // String Assertion failed
     150: astore        6
     152: new           #243                // class java/lang/AssertionError
     155: dup
     156: aload         6
     158: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     161: athrow
     162: new           #57                 // class java/util/ArrayList
     165: dup
     166: invokespecial #129                // Method java/util/ArrayList."<init>":()V
     169: checkcast     #94                 // class java/util/List
     172: astore        5
     174: iconst_3
     175: newarray       int
     177: astore        6
     179: aload_2
     180: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
     183: pop
     184: aload_2
     185: getfield      #248                // Field java/io/StreamTokenizer.ttype:I
     188: bipush        -2
     190: if_icmpne     197
     193: iconst_1
     194: goto          198
     197: iconst_0
     198: istore        7
     200: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
     203: ifeq          225
     206: iload         7
     208: ifne          225
     211: ldc           #241                // String Assertion failed
     213: astore        8
     215: new           #243                // class java/lang/AssertionError
     218: dup
     219: aload         8
     221: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     224: athrow
     225: aload_2
     226: getfield      #252                // Field java/io/StreamTokenizer.nval:D
     229: d2i
     230: istore        7
     232: aload_2
     233: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
     236: pop
     237: aload_2
     238: getfield      #248                // Field java/io/StreamTokenizer.ttype:I
     241: bipush        -3
     243: if_icmpne     250
     246: iconst_1
     247: goto          251
     250: iconst_0
     251: istore        8
     253: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
     256: ifeq          278
     259: iload         8
     261: ifne          278
     264: ldc           #241                // String Assertion failed
     266: astore        9
     268: new           #243                // class java/lang/AssertionError
     271: dup
     272: aload         9
     274: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     277: athrow
     278: aload_2
     279: getfield      #227                // Field java/io/StreamTokenizer.sval:Ljava/lang/String;
     282: astore        8
     284: aload         8
     286: ifnull        397
     289: aload         8
     291: invokevirtual #255                // Method java/lang/String.hashCode:()I
     294: lookupswitch  { // 3
                112785: 328
               3027034: 356
              98619139: 342
               default: 397
          }
     328: aload         8
     330: ldc_w         #257                // String red
     333: invokevirtual #260                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     336: ifne          370
     339: goto          397
     342: aload         8
     344: ldc_w         #262                // String green
     347: invokevirtual #260                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     350: ifne          379
     353: goto          397
     356: aload         8
     358: ldc_w         #264                // String blue
     361: invokevirtual #260                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     364: ifne          388
     367: goto          397
     370: aload         6
     372: iconst_0
     373: iload         7
     375: iastore
     376: goto          417
     379: aload         6
     381: iconst_1
     382: iload         7
     384: iastore
     385: goto          417
     388: aload         6
     390: iconst_2
     391: iload         7
     393: iastore
     394: goto          417
     397: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
     400: ifeq          417
     403: ldc           #241                // String Assertion failed
     405: astore        10
     407: new           #243                // class java/lang/AssertionError
     410: dup
     411: aload         10
     413: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     416: athrow
     417: aload_2
     418: invokestatic  #268                // Method isRgbGroupActive:(Ljava/io/StreamTokenizer;)Z
     421: ifne          179
     424: aload         5
     426: aload         6
     428: invokeinterface #269,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     433: pop
     434: aload_2
     435: invokestatic  #272                // Method isGameContinued:(Ljava/io/StreamTokenizer;)Z
     438: ifne          174
     441: aload_2
     442: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
     445: iconst_m1
     446: if_icmpne     453
     449: iconst_1
     450: goto          454
     453: iconst_0
     454: istore        6
     456: getstatic     #239                // Field kotlin/_Assertions.ENABLED:Z
     459: ifeq          481
     462: iload         6
     464: ifne          481
     467: ldc           #241                // String Assertion failed
     469: astore        7
     471: new           #243                // class java/lang/AssertionError
     474: dup
     475: aload         7
     477: invokespecial #245                // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     480: athrow
     481: new           #131                // class com/shifteleven/adventofcode2023/day02/Game
     484: dup
     485: iload_3
     486: aload         5
     488: invokespecial #275                // Method com/shifteleven/adventofcode2023/day02/Game."<init>":(ILjava/util/List;)V
     491: areturn

  public static final boolean isRgbGroupActive(java.io.StreamTokenizer);
    Code:
       0: aload_0
       1: ldc_w         #283                // String t
       4: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
      11: istore_1
      12: iload_1
      13: i2c
      14: bipush        44
      16: if_icmpne     21
      19: iconst_1
      20: ireturn
      21: aload_0
      22: invokevirtual #286                // Method java/io/StreamTokenizer.pushBack:()V
      25: iconst_0
      26: ireturn

  public static final boolean isGameContinued(java.io.StreamTokenizer);
    Code:
       0: aload_0
       1: ldc_w         #283                // String t
       4: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #224                // Method java/io/StreamTokenizer.nextToken:()I
      11: istore_1
      12: iload_1
      13: i2c
      14: bipush        59
      16: if_icmpne     21
      19: iconst_1
      20: ireturn
      21: aload_0
      22: invokevirtual #286                // Method java/io/StreamTokenizer.pushBack:()V
      25: iconst_0
      26: ireturn

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

Compiled from "App.kt"
public final class com.shifteleven.adventofcode2023.day02.AppKt$main$lines$1 {
  com.shifteleven.adventofcode2023.day02.AppKt$main$lines$1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return
}


package puzzle13

import kotlin.system.measureTimeMillis

fun main() {
    val origamiSolver = OrigamiSolver()

    val time = measureTimeMillis {
        println("number of dots after one fold: ${origamiSolver.countDotsAfterFirstFold()}")
        println("Final Layout is:\n${origamiSolver.foldLayoutEntirely()}")
    }

    println("time: $time")
}

fun List<List<Boolean>>.printLayout(
    fold: FoldInstruction? = null
): String = buildString {
    for ((i, line) in this@printLayout.withIndex()) {
        for ((j, b) in line.withIndex()) {
            if (b) {
                append("#")
            } else if (fold is VerticalFoldInstruction && j == fold.x) {
                append("|")
            } else if (fold is HorizontalFoldInstruction && i == fold.y)  {
                append("—")
            } else {
                append(" ")
            }
        }
        appendLine()
    }
}

data class Position(val x: Int, val y: Int)

sealed interface FoldInstruction {
    fun performFold(layout: List<List<Boolean>>): List<List<Boolean>>
}

data class VerticalFoldInstruction(val x: Int): FoldInstruction {
    override fun performFold(layout: List<List<Boolean>>): List<List<Boolean>> {
        val newLayout = MutableList(layout.size) { MutableList(x) { false } }
        for (j in 0 until x) {
            val verticallySymmetricColumn = layout[0].size - j - 1

            for (i in layout.indices) {
                newLayout[i][j] = layout[i][j] || layout[i][verticallySymmetricColumn]
            }
        }
        return newLayout
            .map { it.toList() }
            .toList()
    }
}

data class HorizontalFoldInstruction(val y: Int): FoldInstruction {
    override fun performFold(layout: List<List<Boolean>>): List<List<Boolean>> {
        val newLayout = MutableList(y) { MutableList(layout[0].size) { false } }
        for (i in y downTo 1){
            val above = y - i
            val under = y + i
            for (j in layout[0].indices) {
                newLayout[y - i][j] = layout.getOrNull(under)?.getOrNull(j)?: false || layout.getOrNull(above)?.getOrNull(j) ?: false
            }
        }

        return newLayout
            .map { it.toList() }
            .toList()
    }
}

fun List<Position>.createLayout(): List<List<Boolean>> = MutableList(this.maxOf { it.y }  + 1) {
    MutableList(this.maxOf { it.x } + 1) { false }
}
    .apply {
        this@createLayout.forEach {
            this[it.y][it.x] = true
        }
    }
    .map { it.toList() }
    .toList()

class OrigamiSolver {
    private val input = OrigamiSolver::class.java.getResource("/input/puzzle13.txt")
        ?.readText()
        ?: ""

    private val dotPosition = input
        .split("\n\n")[0]
        .split("\n")
        .map {
            val (x, y) = it.split(",")
            Position(x.toInt(), y.toInt())
        }

    private val foldingInstructions = input
        .split("\n\n")[1]
        .split("\n")
        .map { s: String ->
            val (axis, value) = s.removePrefix("fold along ").split("=")
            when (axis) {
                "y" -> HorizontalFoldInstruction(value.toInt())
                "x" -> VerticalFoldInstruction(value.toInt())
                else -> error(axis)
            }
        }

    fun countDotsAfterFirstFold(): Int = foldingInstructions[0]
        .performFold(dotPosition.createLayout())
        .flatten()
        .count { it }

    fun foldLayoutEntirely(): String = foldingInstructions
        .fold(dotPosition.createLayout()) { acc, foldInstruction -> foldInstruction.performFold(acc) }.printLayout()
}

Compiled from "OrigamiSolver.kt"
public final class puzzle13.OrigamiSolverKt {
  public static final void main();
    Code:
       0: new           #8                  // class puzzle13/OrigamiSolver
       3: dup
       4: invokespecial #11                 // Method puzzle13/OrigamiSolver."<init>":()V
       7: astore_0
       8: iconst_0
       9: istore_3
      10: invokestatic  #17                 // Method java/lang/System.currentTimeMillis:()J
      13: lstore        4
      15: iconst_0
      16: istore        6
      18: new           #19                 // class java/lang/StringBuilder
      21: dup
      22: invokespecial #20                 // Method java/lang/StringBuilder."<init>":()V
      25: ldc           #22                 // String number of dots after one fold:
      27: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      30: aload_0
      31: invokevirtual #30                 // Method puzzle13/OrigamiSolver.countDotsAfterFirstFold:()I
      34: invokevirtual #33                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      37: invokevirtual #37                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      40: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
      43: swap
      44: invokevirtual #47                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      47: new           #19                 // class java/lang/StringBuilder
      50: dup
      51: invokespecial #20                 // Method java/lang/StringBuilder."<init>":()V
      54: ldc           #49                 // String Final Layout is:\n
      56: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      59: aload_0
      60: invokevirtual #52                 // Method puzzle13/OrigamiSolver.foldLayoutEntirely:()Ljava/lang/String;
      63: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      66: invokevirtual #37                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      69: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
      72: swap
      73: invokevirtual #47                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      76: nop
      77: nop
      78: invokestatic  #17                 // Method java/lang/System.currentTimeMillis:()J
      81: lload         4
      83: lsub
      84: lstore_1
      85: new           #19                 // class java/lang/StringBuilder
      88: dup
      89: invokespecial #20                 // Method java/lang/StringBuilder."<init>":()V
      92: ldc           #54                 // String time:
      94: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      97: lload_1
      98: invokevirtual #57                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     101: invokevirtual #37                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     104: getstatic     #41                 // Field java/lang/System.out:Ljava/io/PrintStream;
     107: swap
     108: invokevirtual #47                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     111: return

  public static final java.lang.String printLayout(java.util.List<? extends java.util.List<java.lang.Boolean>>, puzzle13.FoldInstruction);
    Code:
       0: aload_0
       1: ldc           #72                 // String <this>
       3: invokestatic  #78                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #19                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #20                 // Method java/lang/StringBuilder."<init>":()V
      13: astore_2
      14: aload_2
      15: astore_3
      16: iconst_0
      17: istore        4
      19: aload_0
      20: checkcast     #80                 // class java/lang/Iterable
      23: invokeinterface #84,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore        5
      30: iconst_0
      31: istore        6
      33: aload         5
      35: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          205
      43: iload         6
      45: istore        7
      47: iload         6
      49: iconst_1
      50: iadd
      51: istore        6
      53: aload         5
      55: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: checkcast     #96                 // class java/util/List
      63: astore        8
      65: aload         8
      67: checkcast     #80                 // class java/lang/Iterable
      70: invokeinterface #84,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      75: astore        9
      77: iconst_0
      78: istore        10
      80: aload         9
      82: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          195
      90: iload         10
      92: istore        11
      94: iload         10
      96: iconst_1
      97: iadd
      98: istore        10
     100: aload         9
     102: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     107: checkcast     #98                 // class java/lang/Boolean
     110: invokevirtual #101                // Method java/lang/Boolean.booleanValue:()Z
     113: istore        12
     115: iload         12
     117: ifeq          129
     120: aload_3
     121: ldc           #103                // String #
     123: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     126: goto          191
     129: aload_1
     130: instanceof    #105                // class puzzle13/VerticalFoldInstruction
     133: ifeq          157
     136: iload         11
     138: aload_1
     139: checkcast     #105                // class puzzle13/VerticalFoldInstruction
     142: invokevirtual #108                // Method puzzle13/VerticalFoldInstruction.getX:()I
     145: if_icmpne     157
     148: aload_3
     149: ldc           #110                // String |
     151: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     154: goto          191
     157: aload_1
     158: instanceof    #112                // class puzzle13/HorizontalFoldInstruction
     161: ifeq          185
     164: iload         7
     166: aload_1
     167: checkcast     #112                // class puzzle13/HorizontalFoldInstruction
     170: invokevirtual #115                // Method puzzle13/HorizontalFoldInstruction.getY:()I
     173: if_icmpne     185
     176: aload_3
     177: ldc           #117                // String —
     179: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     182: goto          191
     185: aload_3
     186: ldc           #119                // String
     188: invokevirtual #26                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     191: pop
     192: goto          80
     195: aload_3
     196: bipush        10
     198: invokevirtual #122                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     201: pop
     202: goto          33
     205: nop
     206: aload_2
     207: invokevirtual #37                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     210: areturn

  public static java.lang.String printLayout$default(java.util.List, puzzle13.FoldInstruction, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          8
       6: aconst_null
       7: astore_1
       8: aload_0
       9: aload_1
      10: invokestatic  #140                // Method printLayout:(Ljava/util/List;Lpuzzle13/FoldInstruction;)Ljava/lang/String;
      13: areturn

  public static final java.util.List<java.util.List<java.lang.Boolean>> createLayout(java.util.List<puzzle13.Position>);
    Code:
       0: aload_0
       1: ldc           #72                 // String <this>
       3: invokestatic  #78                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #80                 // class java/lang/Iterable
      10: invokeinterface #84,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore_2
      16: aload_2
      17: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifne          33
      25: new           #145                // class java/util/NoSuchElementException
      28: dup
      29: invokespecial #146                // Method java/util/NoSuchElementException."<init>":()V
      32: athrow
      33: aload_2
      34: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #148                // class puzzle13/Position
      42: astore_3
      43: iconst_0
      44: istore        4
      46: aload_3
      47: invokevirtual #149                // Method puzzle13/Position.getY:()I
      50: istore_3
      51: aload_2
      52: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          93
      60: aload_2
      61: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: checkcast     #148                // class puzzle13/Position
      69: astore        4
      71: iconst_0
      72: istore        5
      74: aload         4
      76: invokevirtual #149                // Method puzzle13/Position.getY:()I
      79: istore        4
      81: iload_3
      82: iload         4
      84: if_icmpge     51
      87: iload         4
      89: istore_3
      90: goto          51
      93: iload_3
      94: iconst_1
      95: iadd
      96: istore_1
      97: new           #151                // class java/util/ArrayList
     100: dup
     101: iload_1
     102: invokespecial #154                // Method java/util/ArrayList."<init>":(I)V
     105: astore_2
     106: iconst_0
     107: istore_3
     108: iload_3
     109: iload_1
     110: if_icmpge     301
     113: iload_3
     114: istore        4
     116: aload_2
     117: iload         4
     119: istore        5
     121: astore        14
     123: iconst_0
     124: istore        6
     126: aload_0
     127: checkcast     #80                 // class java/lang/Iterable
     130: invokeinterface #84,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        7
     137: aload         7
     139: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifne          155
     147: new           #145                // class java/util/NoSuchElementException
     150: dup
     151: invokespecial #146                // Method java/util/NoSuchElementException."<init>":()V
     154: athrow
     155: aload         7
     157: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     162: checkcast     #148                // class puzzle13/Position
     165: astore        8
     167: iconst_0
     168: istore        9
     170: aload         8
     172: invokevirtual #155                // Method puzzle13/Position.getX:()I
     175: istore        8
     177: aload         7
     179: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     184: ifeq          223
     187: aload         7
     189: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     194: checkcast     #148                // class puzzle13/Position
     197: astore        9
     199: iconst_0
     200: istore        10
     202: aload         9
     204: invokevirtual #155                // Method puzzle13/Position.getX:()I
     207: istore        9
     209: iload         8
     211: iload         9
     213: if_icmpge     177
     216: iload         9
     218: istore        8
     220: goto          177
     223: iload         8
     225: iconst_1
     226: iadd
     227: istore        11
     229: new           #151                // class java/util/ArrayList
     232: dup
     233: iload         11
     235: invokespecial #154                // Method java/util/ArrayList."<init>":(I)V
     238: astore        7
     240: iconst_0
     241: istore        8
     243: iload         8
     245: iload         11
     247: if_icmpge     282
     250: iload         8
     252: istore        9
     254: aload         7
     256: iload         9
     258: istore        10
     260: astore        12
     262: iconst_0
     263: istore        13
     265: iconst_0
     266: invokestatic  #159                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     269: aload         12
     271: swap
     272: invokevirtual #163                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     275: pop
     276: iinc          8, 1
     279: goto          243
     282: aload         7
     284: checkcast     #96                 // class java/util/List
     287: nop
     288: aload         14
     290: swap
     291: invokevirtual #163                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     294: pop
     295: iinc          3, 1
     298: goto          108
     301: aload_2
     302: checkcast     #96                 // class java/util/List
     305: astore_1
     306: aload_1
     307: astore_2
     308: iconst_0
     309: istore_3
     310: aload_0
     311: checkcast     #80                 // class java/lang/Iterable
     314: astore        4
     316: iconst_0
     317: istore        5
     319: aload         4
     321: invokeinterface #84,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     326: astore        6
     328: aload         6
     330: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     335: ifeq          391
     338: aload         6
     340: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     345: astore        7
     347: aload         7
     349: checkcast     #148                // class puzzle13/Position
     352: astore        8
     354: iconst_0
     355: istore        9
     357: aload_2
     358: aload         8
     360: invokevirtual #149                // Method puzzle13/Position.getY:()I
     363: invokeinterface #167,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     368: checkcast     #96                 // class java/util/List
     371: aload         8
     373: invokevirtual #155                // Method puzzle13/Position.getX:()I
     376: iconst_1
     377: invokestatic  #159                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     380: invokeinterface #171,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     385: pop
     386: nop
     387: nop
     388: goto          328
     391: nop
     392: nop
     393: aload_1
     394: checkcast     #80                 // class java/lang/Iterable
     397: astore_1
     398: nop
     399: iconst_0
     400: istore_2
     401: aload_1
     402: astore_3
     403: new           #151                // class java/util/ArrayList
     406: dup
     407: aload_1
     408: bipush        10
     410: invokestatic  #177                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     413: invokespecial #154                // Method java/util/ArrayList."<init>":(I)V
     416: checkcast     #179                // class java/util/Collection
     419: astore        4
     421: iconst_0
     422: istore        5
     424: aload_3
     425: invokeinterface #84,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     430: astore        6
     432: aload         6
     434: invokeinterface #90,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     439: ifeq          485
     442: aload         6
     444: invokeinterface #94,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     449: astore        7
     451: aload         4
     453: aload         7
     455: checkcast     #96                 // class java/util/List
     458: astore        8
     460: astore        14
     462: iconst_0
     463: istore        9
     465: aload         8
     467: checkcast     #80                 // class java/lang/Iterable
     470: invokestatic  #183                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     473: aload         14
     475: swap
     476: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     481: pop
     482: goto          432
     485: aload         4
     487: checkcast     #96                 // class java/util/List
     490: nop
     491: checkcast     #80                 // class java/lang/Iterable
     494: invokestatic  #183                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     497: areturn

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

Compiled from "OrigamiSolver.kt"
public final class puzzle13.OrigamiSolver {
  private final java.lang.String input;

  private final java.util.List<puzzle13.Position> dotPosition;

  private final java.util.List<puzzle13.FoldInstruction> foldingInstructions;

  public puzzle13.OrigamiSolver();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: ldc           #2                  // class puzzle13/OrigamiSolver
       7: ldc           #10                 // String /input/puzzle13.txt
       9: invokevirtual #16                 // Method java/lang/Class.getResource:(Ljava/lang/String;)Ljava/net/URL;
      12: astore_1
      13: aload_1
      14: ifnull        44
      17: aload_1
      18: astore_3
      19: getstatic     #22                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      22: astore        4
      24: aload_3
      25: invokestatic  #28                 // Method kotlin/io/TextStreamsKt.readBytes:(Ljava/net/URL;)[B
      28: astore        5
      30: new           #30                 // class java/lang/String
      33: dup
      34: aload         5
      36: aload         4
      38: invokespecial #33                 // Method java/lang/String."<init>":([BLjava/nio/charset/Charset;)V
      41: goto          46
      44: ldc           #35                 // String
      46: putfield      #39                 // Field input:Ljava/lang/String;
      49: aload_0
      50: aload_0
      51: getfield      #39                 // Field input:Ljava/lang/String;
      54: checkcast     #41                 // class java/lang/CharSequence
      57: iconst_1
      58: anewarray     #30                 // class java/lang/String
      61: astore_1
      62: aload_1
      63: iconst_0
      64: ldc           #43                 // String \n\n
      66: aastore
      67: aload_1
      68: iconst_0
      69: iconst_0
      70: bipush        6
      72: aconst_null
      73: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      76: iconst_0
      77: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      82: checkcast     #41                 // class java/lang/CharSequence
      85: iconst_1
      86: anewarray     #30                 // class java/lang/String
      89: astore_1
      90: aload_1
      91: iconst_0
      92: ldc           #57                 // String \n
      94: aastore
      95: aload_1
      96: iconst_0
      97: iconst_0
      98: bipush        6
     100: aconst_null
     101: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     104: checkcast     #59                 // class java/lang/Iterable
     107: astore_1
     108: astore        14
     110: iconst_0
     111: istore_2
     112: aload_1
     113: astore_3
     114: new           #61                 // class java/util/ArrayList
     117: dup
     118: aload_1
     119: bipush        10
     121: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     124: invokespecial #70                 // Method java/util/ArrayList."<init>":(I)V
     127: checkcast     #72                 // class java/util/Collection
     130: astore        4
     132: iconst_0
     133: istore        5
     135: aload_3
     136: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        6
     143: aload         6
     145: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          260
     153: aload         6
     155: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: astore        7
     162: aload         4
     164: aload         7
     166: checkcast     #30                 // class java/lang/String
     169: astore        8
     171: astore        15
     173: iconst_0
     174: istore        9
     176: aload         8
     178: checkcast     #41                 // class java/lang/CharSequence
     181: iconst_1
     182: anewarray     #30                 // class java/lang/String
     185: astore        10
     187: aload         10
     189: iconst_0
     190: ldc           #88                 // String ,
     192: aastore
     193: aload         10
     195: iconst_0
     196: iconst_0
     197: bipush        6
     199: aconst_null
     200: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     203: astore        11
     205: aload         11
     207: iconst_0
     208: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     213: checkcast     #30                 // class java/lang/String
     216: astore        10
     218: aload         11
     220: iconst_1
     221: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     226: checkcast     #30                 // class java/lang/String
     229: astore        12
     231: new           #90                 // class puzzle13/Position
     234: dup
     235: aload         10
     237: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     240: aload         12
     242: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     245: invokespecial #99                 // Method puzzle13/Position."<init>":(II)V
     248: aload         15
     250: swap
     251: invokeinterface #103,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     256: pop
     257: goto          143
     260: aload         4
     262: checkcast     #51                 // class java/util/List
     265: nop
     266: aload         14
     268: swap
     269: putfield      #107                // Field dotPosition:Ljava/util/List;
     272: aload_0
     273: aload_0
     274: getfield      #39                 // Field input:Ljava/lang/String;
     277: checkcast     #41                 // class java/lang/CharSequence
     280: iconst_1
     281: anewarray     #30                 // class java/lang/String
     284: astore_1
     285: aload_1
     286: iconst_0
     287: ldc           #43                 // String \n\n
     289: aastore
     290: aload_1
     291: iconst_0
     292: iconst_0
     293: bipush        6
     295: aconst_null
     296: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     299: iconst_1
     300: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     305: checkcast     #41                 // class java/lang/CharSequence
     308: iconst_1
     309: anewarray     #30                 // class java/lang/String
     312: astore_1
     313: aload_1
     314: iconst_0
     315: ldc           #57                 // String \n
     317: aastore
     318: aload_1
     319: iconst_0
     320: iconst_0
     321: bipush        6
     323: aconst_null
     324: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     327: checkcast     #59                 // class java/lang/Iterable
     330: astore_1
     331: astore        14
     333: iconst_0
     334: istore_2
     335: aload_1
     336: astore_3
     337: new           #61                 // class java/util/ArrayList
     340: dup
     341: aload_1
     342: bipush        10
     344: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     347: invokespecial #70                 // Method java/util/ArrayList."<init>":(I)V
     350: checkcast     #72                 // class java/util/Collection
     353: astore        4
     355: iconst_0
     356: istore        5
     358: aload_3
     359: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     364: astore        6
     366: aload         6
     368: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     373: ifeq          548
     376: aload         6
     378: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     383: astore        7
     385: aload         4
     387: aload         7
     389: checkcast     #30                 // class java/lang/String
     392: astore        8
     394: astore        15
     396: iconst_0
     397: istore        9
     399: aload         8
     401: ldc           #109                // String fold along
     403: checkcast     #41                 // class java/lang/CharSequence
     406: invokestatic  #113                // Method kotlin/text/StringsKt.removePrefix:(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String;
     409: checkcast     #41                 // class java/lang/CharSequence
     412: iconst_1
     413: anewarray     #30                 // class java/lang/String
     416: astore        10
     418: aload         10
     420: iconst_0
     421: ldc           #115                // String =
     423: aastore
     424: aload         10
     426: iconst_0
     427: iconst_0
     428: bipush        6
     430: aconst_null
     431: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     434: astore        11
     436: aload         11
     438: iconst_0
     439: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     444: checkcast     #30                 // class java/lang/String
     447: astore        10
     449: aload         11
     451: iconst_1
     452: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     457: checkcast     #30                 // class java/lang/String
     460: astore        12
     462: aload         10
     464: astore        13
     466: aload         13
     468: ldc           #117                // String y
     470: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     473: ifeq          494
     476: new           #125                // class puzzle13/HorizontalFoldInstruction
     479: dup
     480: aload         12
     482: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     485: invokespecial #126                // Method puzzle13/HorizontalFoldInstruction."<init>":(I)V
     488: checkcast     #128                // class puzzle13/FoldInstruction
     491: goto          535
     494: aload         13
     496: ldc           #130                // String x
     498: invokestatic  #123                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     501: ifeq          522
     504: new           #132                // class puzzle13/VerticalFoldInstruction
     507: dup
     508: aload         12
     510: invokestatic  #96                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     513: invokespecial #133                // Method puzzle13/VerticalFoldInstruction."<init>":(I)V
     516: checkcast     #128                // class puzzle13/FoldInstruction
     519: goto          535
     522: new           #135                // class java/lang/IllegalStateException
     525: dup
     526: aload         10
     528: invokevirtual #139                // Method java/lang/Object.toString:()Ljava/lang/String;
     531: invokespecial #142                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     534: athrow
     535: nop
     536: aload         15
     538: swap
     539: invokeinterface #103,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     544: pop
     545: goto          366
     548: aload         4
     550: checkcast     #51                 // class java/util/List
     553: nop
     554: aload         14
     556: swap
     557: putfield      #145                // Field foldingInstructions:Ljava/util/List;
     560: return

  public final int countDotsAfterFirstFold();
    Code:
       0: aload_0
       1: getfield      #145                // Field foldingInstructions:Ljava/util/List;
       4: iconst_0
       5: invokeinterface #55,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      10: checkcast     #128                // class puzzle13/FoldInstruction
      13: aload_0
      14: getfield      #107                // Field dotPosition:Ljava/util/List;
      17: invokestatic  #173                // Method puzzle13/OrigamiSolverKt.createLayout:(Ljava/util/List;)Ljava/util/List;
      20: invokeinterface #176,  2          // InterfaceMethod puzzle13/FoldInstruction.performFold:(Ljava/util/List;)Ljava/util/List;
      25: checkcast     #59                 // class java/lang/Iterable
      28: invokestatic  #180                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
      31: checkcast     #59                 // class java/lang/Iterable
      34: astore_1
      35: nop
      36: iconst_0
      37: istore_2
      38: aload_1
      39: instanceof    #72                 // class java/util/Collection
      42: ifeq          61
      45: aload_1
      46: checkcast     #72                 // class java/util/Collection
      49: invokeinterface #183,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      54: ifeq          61
      57: iconst_0
      58: goto          122
      61: iconst_0
      62: istore_3
      63: aload_1
      64: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      69: astore        4
      71: aload         4
      73: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      78: ifeq          121
      81: aload         4
      83: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      88: astore        5
      90: aload         5
      92: checkcast     #185                // class java/lang/Boolean
      95: invokevirtual #188                // Method java/lang/Boolean.booleanValue:()Z
      98: istore        6
     100: iconst_0
     101: istore        7
     103: iload         6
     105: ifeq          71
     108: iinc          3, 1
     111: iload_3
     112: ifge          71
     115: invokestatic  #191                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     118: goto          71
     121: iload_3
     122: ireturn

  public final java.lang.String foldLayoutEntirely();
    Code:
       0: aload_0
       1: getfield      #145                // Field foldingInstructions:Ljava/util/List;
       4: checkcast     #59                 // class java/lang/Iterable
       7: astore_1
       8: aload_0
       9: getfield      #107                // Field dotPosition:Ljava/util/List;
      12: invokestatic  #173                // Method puzzle13/OrigamiSolverKt.createLayout:(Ljava/util/List;)Ljava/util/List;
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_2
      19: astore        4
      21: aload_1
      22: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      27: astore        5
      29: aload         5
      31: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          76
      39: aload         5
      41: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        6
      48: aload         4
      50: aload         6
      52: checkcast     #128                // class puzzle13/FoldInstruction
      55: astore        7
      57: astore        8
      59: iconst_0
      60: istore        9
      62: aload         7
      64: aload         8
      66: invokeinterface #176,  2          // InterfaceMethod puzzle13/FoldInstruction.performFold:(Ljava/util/List;)Ljava/util/List;
      71: astore        4
      73: goto          29
      76: aload         4
      78: aconst_null
      79: iconst_1
      80: aconst_null
      81: invokestatic  #203                // Method puzzle13/OrigamiSolverKt.printLayout$default:(Ljava/util/List;Lpuzzle13/FoldInstruction;ILjava/lang/Object;)Ljava/lang/String;
      84: areturn
}