class Day13(input: List) { data class Layer(val depth: Int, val range: Int) { fun caughtAt(time: Int): Boolean = (time + depth) % ((range - 1) * 2) == 0 } private val layers = parseInput(input) fun solvePart1(): Int = layers .filter { it.caughtAt(0) } .sumBy { it.depth * it.range } fun solvePart2(): Int = generateSequence(0, Int::inc) .filter { time -> layers.none { it.caughtAt(time) } } .first() private fun parseInput(input: List): List = input .map { it.split(": ") } .map { Layer(it[0].toInt(), it[1].toInt()) } }