-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.py
48 lines (42 loc) · 1.3 KB
/
solution.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
data = open("data.txt").read().split("\n")
# Part 1
rect = {}
for row in data:
a =row.split(" @ ")[1].split(": ")
xy = list(map(int, a[0].split(",")))
wh = list(map(int, a[1].split("x")))
for y in range(xy[1], xy[1] + wh[1]):
for x in range(xy[0], xy[0] + wh[0]):
coords = str(x) + "x" + str(y)
rect[coords] = rect.get(coords, 0) + 1
counter = 0
for k,v in rect.items():
if v>1:
counter += 1
print(counter)
# Part 2
rect = {}
for row in data:
a =row.split(" @ ")[1].split(": ")
xy = list(map(int, a[0].split(",")))
wh = list(map(int, a[1].split("x")))
id = row.split(" @ ")[0]
for y in range(xy[1], xy[1] + wh[1]):
for x in range(xy[0], xy[0] + wh[0]):
coords = str(x) + "x" + str(y)
rect[coords] = rect.get(coords, []) + [id]
for row in data:
a =row.split(" @ ")[1].split(": ")
xy = list(map(int, a[0].split(",")))
wh = list(map(int, a[1].split("x")))
id = row.split(" @ ")[0]
colliding = False
for y in range(xy[1], xy[1] + wh[1]):
for x in range(xy[0], xy[0] + wh[0]):
coords = str(x) + "x" + str(y)
if len(rect[coords])>1 or id not in rect[coords]:
colliding = True
break
if not colliding:
print(id)
break