-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day030.py
107 lines (96 loc) · 2.43 KB
/
Day030.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import csv
file = "test.txt"
lred = []
lblue = []
up = "U"
right = "R"
down = "D"
left = "L"
def start():
global locx, locy
locx = 0
locy = 0
def compare():
mindist = float('inf')
for collision in collisionlist:
a, b = collision.split(",")
a, b = int(a), int(b)
tempdist = abs(a) + abs(b)
if tempdist < mindist and tempdist != 0:
mindist = tempdist
return mindist
start()
with open (file, 'r') as csvfile:
allwires = list(csv.reader(csvfile, delimiter=","))
red = list(allwires[0])
blue = list(allwires[1])
for i in range(0,len(red)):
if red[i][0] == up:
j = int(red[i][1:])
count = 0
while (count < j):
locy += 1
lred.append(str(locx) + "," + str(locy))
count += 1
elif red[i][0] == right:
j = int(red[i][1:])
count = 0
while (count < j):
locx += 1
lred.append(str(locx) + "," + str(locy))
count += 1
elif red[i][0] == down:
j = int(red[i][1:])
count = 0
while (count < j):
locy -= 1
lred.append(str(locx) + "," + str(locy))
count += 1
elif red[i][0] == left:
j = int(red[i][1:])
count = 0
while (count < j):
locx -= 1
lred.append(str(locx) + "," + str(locy))
count += 1
else:
print("fuck")
start()
for i in range(0,len(blue)):
if blue[i][0] == up:
j = int(blue[i][1:])
count = 0
while (count < j):
locy += 1
lblue.append(str(locx) + "," + str(locy))
count += 1
elif blue[i][0] == right:
j = int(blue[i][1:])
count = 0
while (count < j):
locx += 1
lblue.append(str(locx) + "," + str(locy))
count += 1
elif blue[i][0] == down:
j = int(blue[i][1:])
count = 0
while (count < j):
locy -= 1
lblue.append(str(locx) + "," + str(locy))
count += 1
elif blue[i][0] == left:
j = int(blue[i][1:])
count = 0
while (count < j):
locx -= 1
lblue.append(str(locx) + "," + str(locy))
count += 1
else:
print("fuck")
print(lred)
print(lblue)
collisionlist = []
lblue_set = set(lblue)
collisionlist = [item for item in lred if item in lblue_set]
print(collisionlist)
print(compare())