You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
lines = open("input.txt", "r").read().splitlines()
|
|
|
|
|
|
def parse_lines(lines: list) -> (set, set):
|
|
sensors = []
|
|
beacons = []
|
|
for line in lines:
|
|
_, _, sx, sy, _, _, _, _, bx, by = line.split(" ")
|
|
sensors.append([int(sx.split("=")[1][:-1]), int(sy.split("=")[1][:-1])])
|
|
beacons.append([int(bx.split("=")[1][:-1]), int(by.split("=")[1])])
|
|
return sensors, beacons
|
|
|
|
|
|
def manhatten(a, b):
|
|
return abs(a[0] - b[0]) + abs(a[1] - b[1])
|
|
|
|
|
|
critical = 2000000
|
|
sensors, beacons = parse_lines(lines)
|
|
taken = set()
|
|
critical_beacons = set(tuple(x) for x in beacons if x[1] == critical)
|
|
print(critical_beacons)
|
|
for i in range(len(sensors)):
|
|
print(i)
|
|
s = sensors[i]
|
|
b = beacons[i]
|
|
d = manhatten(s, b)
|
|
min_y, max_y = s[1] - d, s[1] + d
|
|
if min_y <= critical <= max_y:
|
|
critical_d = abs(s[1] - critical)
|
|
critical_reach = d - critical_d
|
|
taken.update(
|
|
(x, critical)
|
|
for x in range(s[0] - critical_reach, s[0] + critical_reach + 1)
|
|
)
|
|
|
|
print(len(taken) - len(critical_beacons))
|