There was an error while loading. Please reload this page.
2 parents 46e03b9 + 7824b5e commit 6946d12Copy full SHA for 6946d12
src/main/kotlin/io/dmitrijs/aoc2022/Day23.kt
@@ -21,7 +21,7 @@ class Day23(input: List<String>) {
21
}
22
23
private class Grid(input: List<Point>) {
24
- private var elves = input.toSet()
+ private val elves = input.toMutableSet()
25
private var sides = Direction.values().toList()
26
27
val emptyTiles get(): Int {
@@ -49,9 +49,15 @@ class Day23(input: List<String>) {
49
val old = moving.values.toSet()
50
val new = moving.keys
51
52
- elves = elves - old + new
+ elves.apply {
53
+ removeAll(old)
54
+ addAll(new)
55
+ }
56
sides = sides.drop(1) + sides.first()
57
58
+ // Alternatively can be immutable, but mutable structure is faster.
59
+ // elves = elves - old + new
60
+
61
return new.size
62
63
0 commit comments