fun findMatches(input: Map, delay: Int = 0) = input.entries.filter { (delay + it.key) % (2 * (it.value - 1)) == 0 } fun getSeverity(input: Map, delay: Int = 0) = findMatches(input, delay).sumBy { it.key * it.value } fun getMinDelay(input: Map) = (0..10000000).asSequence().first { findMatches(input, it).isEmpty() } fun main(args: Array) { val rawInput = resourceToList("day13_packet_scanners.txt") val input = rawInput.map { it.split(": ") }.associate { it[0].toInt() to it[1].toInt() } println(getSeverity(input)) println(getMinDelay(input)) }