Compare commits

...

2 Commits

Author SHA1 Message Date
e63c471b96 p1 clean 2022-12-15 16:05:38 +02:00
1d06422f87 day 15 p1 and p2 partial 2022-12-15 08:00:48 +02:00

48
15/o.py Normal file
View File

@@ -0,0 +1,48 @@
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))