(kotlin) day 13 wip
This commit is contained in:
parent
a1cf3ad627
commit
606f4f2ace
32
13/main_2.kt
32
13/main_2.kt
|
@ -85,24 +85,26 @@ class Main() {
|
||||||
}
|
}
|
||||||
var positions = HashSet<Pair<Int, Int>>(trains.size)
|
var positions = HashSet<Pair<Int, Int>>(trains.size)
|
||||||
positions.addAll(trains.map{ t -> Pair(t.x, t.y) })
|
positions.addAll(trains.map{ t -> Pair(t.x, t.y) })
|
||||||
var current = 0
|
var crash = false
|
||||||
while (trains.filter{ it.alive }.size > 1) {
|
var remove = Pair(-1, -1)
|
||||||
while (positions.size == trains.filter{ it.alive }.size) {
|
while (trains.size > 1) {
|
||||||
if (!trains[current].alive)
|
for ((i, train) in trains.withIndex()) {
|
||||||
continue
|
trains[i] = moveTrain(train)
|
||||||
trains[current] = moveTrain(trains[current])
|
|
||||||
positions.clear()
|
positions.clear()
|
||||||
positions.addAll(trains.filter{ it.alive }.map{ t -> Pair(t.x, t.y) })
|
positions.addAll(trains.map{ t -> Pair(t.x, t.y) })
|
||||||
current = (current + 1) % trains.size
|
if (trains.size > positions.size) {
|
||||||
|
remove = cleanUpAfterCrash(trains)
|
||||||
|
println("removing $remove")
|
||||||
|
crash = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (crash) {
|
||||||
|
trains.removeAll(listOf(trains[remove.first], trains[remove.second]))
|
||||||
|
crash = false
|
||||||
}
|
}
|
||||||
val remove = cleanUpAfterCrash(trains)
|
|
||||||
println("removing $remove")
|
|
||||||
trains[remove.first].alive = false
|
|
||||||
trains[remove.second].alive = false
|
|
||||||
|
|
||||||
positions.clear()
|
|
||||||
positions.addAll(trains.filter{ it.alive }.map{ t -> Pair(t.x, t.y) })
|
|
||||||
}
|
}
|
||||||
|
println("${trains[0].x},${trains[0].y}")
|
||||||
|
println("done")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user