Files
aoc/2022/15/o.py
2023-11-30 19:20:34 +02:00

49 lines
1.0 KiB
Python

import os
input = open(os.path.dirname(__file__) +
"/input.txt", "r").readlines()
beacons = []
sensors = []
distance = []
for line in input:
l = line.strip().split()
sx = int(l[2].split('=')[1].split(',')[0])
sy = int(l[3].split('=')[1].split(':')[0])
bx = int(l[8].split('=')[1].split(',')[0])
by = int(l[9].split('=')[1])
d = abs(bx-sx)+abs(by-sy)
distance.append(d)
beacons.append((bx, by))
sensors.append((sx, sy))
print(sx, sy, bx, by, d)
def getcoverage(b, Y):
coverage = set()
(x, y) = sensors[b]
d0 = distance[i]
print("check", x, y, d0)
for X in range(x-d0, x+d0):
if (abs(x-X)+abs(y-Y)) <= d0:
coverage.add((X, Y))
return coverage
testy = 2000000
fullcoverage = set()
for i in range(len(sensors)):
cov = getcoverage(i, testy)
fullcoverage.update(cov)
testset = set()
for s in fullcoverage:
if s[1] == testy:
testset.add(s)
nonbeacons = testset.difference(set(beacons))
print(len(nonbeacons))