Commit 80ea850d authored by Kevin Turner's avatar Kevin Turner

Day 3, Part 2

parent 1fc3a6cf
......@@ -113,6 +113,8 @@ fun findCollisions(claims: List<Claim>): List<Rect> {
val leftToRight = claims.sortedBy { claim -> claim.left }
val collisions = mutableListOf<Rect>()
val notCollidedYet = claims.toMutableSet()
for ((currentIndex, claim) in leftToRight.withIndex()) {
for (hazard in leftToRight.listIterator(currentIndex + 1)) {
if (hazard.left > claim.right) {
......@@ -121,10 +123,15 @@ fun findCollisions(claims: List<Claim>): List<Rect> {
val collision = claim.collision(hazard)
if (collision != null) {
collisions.add(collision)
notCollidedYet.remove(hazard)
notCollidedYet.remove(claim)
}
}
}
println("These ${notCollidedYet.size} never collided!")
notCollidedYet.forEach { println(it) }
return collisions.toList()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment