### re: Advent of Code 2019 Solution Megathread - Day 3: Crossed Wires VIEW POST

Today was a challenging Day 3! I was definitely overthinking this problem, and I also ended up accidentally deleting my Part 1 implementation before moving on to Part 2...it's one of those days 🙃. Here's what I got:

def get_path(wire):
i = j = 0
step = 1
path = {}
for visit in wire:
dir, position = visit, int(visit[1:])
x = y = 0
if dir == 'U':
x = -1
elif dir == 'D':
x = 1
elif dir == 'L':
y = -1
elif dir == 'R':
y = 1
else:
raise Exception('Unexpected direction')

for _ in range(position):
i += x
j += y
path[(i, j)] = step
step += 1

return path

def dist(p, q):
return abs(p - q) + abs(p - q)

def calculate_min_distance(intersections):
return min(dist(point, (0, 0)) for point in intersections)

def calculate_min_steps(intersections, steps_a, steps_b):
min_steps = float('inf')
for point in intersections:
if point not in steps_a or point not in steps_b:
raise Exception('Not an shared path intersection.')
min_steps = min(min_steps, steps_a[point] + steps_b[point])
return min_steps  