File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -41,15 +41,18 @@ object Day21 {
41
41
42
42
private fun stepPossibilities (numberOfSteps : Int ): Int {
43
43
val steps = LinkedList (listOf (startingStep()))
44
+ val possible = mutableListOf<Vector2 >()
44
45
45
46
while (steps.isNotEmpty()) {
46
47
val current = steps.removeFirst()
47
48
48
- if (current.stepCount == numberOfSteps) return steps.size + 1
49
- else steps.addAll(neighbors(current).filterNot { steps.contains(it) })
49
+ if (current.stepCount > numberOfSteps) break
50
+ if ((current.stepCount + numberOfSteps) % 2 == 0 ) possible.add(current.position)
51
+
52
+ steps.addAll(neighbors(current).filterNot { steps.contains(it) || possible.contains(it.position) })
50
53
}
51
54
52
- throw Exception ( " Couldn't find the number of step possibilities for $numberOfSteps steps " )
55
+ return possible.size
53
56
}
54
57
55
58
fun part1 () = println (stepPossibilities(64 ))
You can’t perform that action at this time.
0 commit comments