day 03
perfectly spherical houses in a vacuum
approach
a step function turns one arrow into a move on a coordinate pair, and every visited position goes into a set.
part 1 walks a single position through the instructions and returns the size of the set. part 2 keeps two positions in a list and alternates between them with i % 2, adding both paths to the same set.
the trick
two walkers are just two positions indexed by the parity of the instruction.
python
def part2(instructions):
dirs = [[0, 0], [0, 0]]
s = {(0, 0)}
for i in range(len(instructions)):
santa = i % 2
r, c = step(*dirs[santa], instructions[i])
dirs[santa][0] = r
dirs[santa][1] = c
s.add((r, c))
return len(s)