Compare commits
2 Commits
f96520e34a
...
e63c471b96
| Author | SHA1 | Date | |
|---|---|---|---|
| e63c471b96 | |||
| 1d06422f87 |
48
15/o.py
Normal file
48
15/o.py
Normal 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))
|
||||
Reference in New Issue
Block a user