-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_3.py
53 lines (42 loc) · 1.16 KB
/
day_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
f = open("day_3_input.txt", "r")
inputs = f.read()
split = inputs.split("\n")
input1 = split[0].split(",")
input2 = split[1].split(",")
def find_path(input_list):
direction = [i[0] for i in input_list]
magnitude = [int(i[1:]) for i in input_list]
movement_dict = dict(zip(direction, magnitude))
x = 0
y = 0
positions = []
for i in movement_dict.keys():
if i == "U":
for j in list(range(1,movement_dict[i] + 1)):
positions.append((x, y + j))
y += movement_dict[i]
elif i == "D":
for j in list(range(1, movement_dict[i] + 1)):
positions.append((x, y - j))
y -= movement_dict[i]
elif i == "R":
for j in list(range(1, movement_dict[i] + 1)):
positions.append((x + j, y))
x += movement_dict[i]
else:
for j in list(range(1, movement_dict[i] + 1)):
positions.append((x - j, y))
x -= movement_dict[i]
return positions
path1 = find_path(input1)
path2 = find_path(input2)
print(path1)
print(path2)
def find_min_intersection(list1, list2):
intersections = []
for i in list1:
if i in list2:
intersections.append(i)
return [sum((tup)) for tup in intersections]
crosses = find_min_intersection(path1, path2)
print(crosses)