-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15_part1.py
52 lines (35 loc) · 1.1 KB
/
15_part1.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
import os
import sys
lines = open(0).readlines()
sensorsx = []
sensorsy = []
sensorsr = []
beacons= []
xmin = sys.maxsize
xmax = 0
def mdist(a, b, c, d):
return abs(a-c) + abs(b-d)
g_y = 2000000
for i in lines:
i = i.rstrip('\n').lstrip("Sensor at ").replace("x=", "").replace(", y=", " ").split(": closest beacon is at ")
sensor = [*map(int, i[0].split(" "))]
beacon = [*map(int, i[1].split(" "))]
dist = mdist(sensor[0], sensor[1], beacon[0], beacon[1])
sensorsx.append(sensor[0])
sensorsy.append(sensor[1])
sensorsr.append(dist)
beacons.append(beacon)
if sensor[0] + dist > xmax:
xmax = sensor[0] + dist
if sensor[0] - dist < xmin:
xmin = sensor[0] - dist
interval = [0 for x in range(xmin, xmax)]
for i in range(len(sensorsx)):
sensor = [sensorsx[i], sensorsy[i]]
dist = sensorsr[i]
ydist = abs(sensor[1] - g_y)
for j in range(sensor[0] - dist + ydist , sensor[0] + dist - ydist + 1):
if [j, g_y] not in beacons:
interval[j-xmin] = 1
count = 0
print(sum(interval ))