day(11): refactor
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
20016a3582
commit
dbc8b26446
1 changed files with 2 additions and 13 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue