1
0
Fork 0

day(11): refactor

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2021-12-11 20:57:57 +01:00
parent 20016a3582
commit dbc8b26446

View file

@ -55,25 +55,14 @@ fun step(octopuses: MutableList<MutableList<Int>>): Int {
} }
fun part1(input: List<List<Int>>): Int { fun part1(input: List<List<Int>>): Int {
var flashes = 0
val octopuses = input.map { row -> row.toMutableList() }.toMutableList() val octopuses = input.map { row -> row.toMutableList() }.toMutableList()
return (1..100).sumOf { step(octopuses) }
repeat(100) {
flashes += step(octopuses)
}
return flashes
} }
fun part2(input: List<List<Int>>): Int { fun part2(input: List<List<Int>>): Int {
var i = 1
val octopuses = input.map { row -> row.toMutableList() }.toMutableList() val octopuses = input.map { row -> row.toMutableList() }.toMutableList()
val count = octopuses.size * octopuses[0].size val count = octopuses.size * octopuses[0].size
return (1..Int.MAX_VALUE).first { step(octopuses) == count }
while (step(octopuses) != count) {
i++
}
return i
} }
fun main() { fun main() {