Compare commits
No commits in common. "7b40516b66b3a3bc09f7a132c7b69ff77d73a83a" and "37e5ab92e08dcffb9664c004c1e5145e40be4812" have entirely different histories.
7b40516b66
...
37e5ab92e0
@ -1,35 +0,0 @@
|
|||||||
import pyclipper # https://pypi.org/project/pyclipper/
|
|
||||||
|
|
||||||
data = []
|
|
||||||
for line in open("input"):
|
|
||||||
words = line.replace(":", "").replace(",","").split()
|
|
||||||
coords = [int(w[w.index('=')+1:]) for w in words if '=' in w]
|
|
||||||
data.append(coords)
|
|
||||||
|
|
||||||
|
|
||||||
pc = pyclipper.Pyclipper()
|
|
||||||
for sx,sy,bx,by in data:
|
|
||||||
dx = abs(sx-bx)
|
|
||||||
dy = abs(sy-by)
|
|
||||||
d = dx+dy
|
|
||||||
pc.AddPath([(sx+d,sy),(sx,sy+d),(sx-d,sy),(sx,sy-d)], pyclipper.PT_CLIP, closed=True)
|
|
||||||
|
|
||||||
M = 4000000
|
|
||||||
pc.AddPath([(0,0),(M,0),(M,M),(0,M)], pyclipper.PT_SUBJECT, closed=True)
|
|
||||||
|
|
||||||
solution = pc.Execute(pyclipper.CT_DIFFERENCE, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)
|
|
||||||
|
|
||||||
# should return a single small polygon shaped like a diamond
|
|
||||||
# the answer we want is the point at the center of the diamond
|
|
||||||
|
|
||||||
assert len(solution) == 1
|
|
||||||
assert pyclipper.Area(solution[0]) < 4
|
|
||||||
|
|
||||||
def avg(ns):
|
|
||||||
return sum(ns)/len(ns)
|
|
||||||
|
|
||||||
for p in solution:
|
|
||||||
x = avg([x for x,y in p])
|
|
||||||
y = avg([y for x,y in p])
|
|
||||||
print(x,y)
|
|
||||||
print("frequency =",M*x + y)
|
|
23
day15/input
23
day15/input
@ -1,23 +0,0 @@
|
|||||||
Sensor at x=325337, y=2568863: closest beacon is at x=-518661, y=2000000
|
|
||||||
Sensor at x=3988825, y=837820: closest beacon is at x=4305648, y=2127118
|
|
||||||
Sensor at x=1611311, y=2053174: closest beacon is at x=2827226, y=1579510
|
|
||||||
Sensor at x=101890, y=3940049: closest beacon is at x=955472, y=3457514
|
|
||||||
Sensor at x=3962702, y=2558425: closest beacon is at x=4226981, y=2604726
|
|
||||||
Sensor at x=2957890, y=2160813: closest beacon is at x=2827226, y=1579510
|
|
||||||
Sensor at x=3907456, y=3325610: closest beacon is at x=3696221, y=3226373
|
|
||||||
Sensor at x=3354177, y=3435919: closest beacon is at x=3696221, y=3226373
|
|
||||||
Sensor at x=3997379, y=3071868: closest beacon is at x=3696221, y=3226373
|
|
||||||
Sensor at x=145143, y=1714962: closest beacon is at x=-518661, y=2000000
|
|
||||||
Sensor at x=611563, y=3148864: closest beacon is at x=955472, y=3457514
|
|
||||||
Sensor at x=3080405, y=3904777: closest beacon is at x=3696221, y=3226373
|
|
||||||
Sensor at x=644383, y=10732: closest beacon is at x=364635, y=-294577
|
|
||||||
Sensor at x=3229566, y=1694167: closest beacon is at x=2827226, y=1579510
|
|
||||||
Sensor at x=1600637, y=3984884: closest beacon is at x=955472, y=3457514
|
|
||||||
Sensor at x=2959765, y=2820860: closest beacon is at x=2491502, y=2897876
|
|
||||||
Sensor at x=2235330, y=3427797: closest beacon is at x=2491502, y=2897876
|
|
||||||
Sensor at x=2428996, y=210881: closest beacon is at x=2827226, y=1579510
|
|
||||||
Sensor at x=369661, y=687805: closest beacon is at x=364635, y=-294577
|
|
||||||
Sensor at x=3558476, y=2123614: closest beacon is at x=4305648, y=2127118
|
|
||||||
Sensor at x=3551529, y=2825104: closest beacon is at x=3696221, y=3226373
|
|
||||||
Sensor at x=64895, y=3577: closest beacon is at x=364635, y=-294577
|
|
||||||
Sensor at x=3079531, y=1538659: closest beacon is at x=2827226, y=1579510
|
|
14
day15/sample
14
day15/sample
@ -1,14 +0,0 @@
|
|||||||
Sensor at x=2, y=18: closest beacon is at x=-2, y=15
|
|
||||||
Sensor at x=9, y=16: closest beacon is at x=10, y=16
|
|
||||||
Sensor at x=13, y=2: closest beacon is at x=15, y=3
|
|
||||||
Sensor at x=12, y=14: closest beacon is at x=10, y=16
|
|
||||||
Sensor at x=10, y=20: closest beacon is at x=10, y=16
|
|
||||||
Sensor at x=14, y=17: closest beacon is at x=10, y=16
|
|
||||||
Sensor at x=8, y=7: closest beacon is at x=2, y=10
|
|
||||||
Sensor at x=2, y=0: closest beacon is at x=2, y=10
|
|
||||||
Sensor at x=0, y=11: closest beacon is at x=2, y=10
|
|
||||||
Sensor at x=20, y=14: closest beacon is at x=25, y=17
|
|
||||||
Sensor at x=17, y=20: closest beacon is at x=21, y=22
|
|
||||||
Sensor at x=16, y=7: closest beacon is at x=15, y=3
|
|
||||||
Sensor at x=14, y=3: closest beacon is at x=15, y=3
|
|
||||||
Sensor at x=20, y=1: closest beacon is at x=15, y=3
|
|
70
day15/sol.py
70
day15/sol.py
@ -1,70 +0,0 @@
|
|||||||
data = []
|
|
||||||
for line in open("input"):
|
|
||||||
words = line.replace(":", "").replace(",","").split()
|
|
||||||
coords = [int(w[w.index('=')+1:]) for w in words if '=' in w]
|
|
||||||
data.append(coords)
|
|
||||||
#print(data)
|
|
||||||
|
|
||||||
none = set()
|
|
||||||
|
|
||||||
Y = 10
|
|
||||||
Y = 2000000
|
|
||||||
|
|
||||||
for sx,sy,bx,by in data:
|
|
||||||
dx = abs(sx-bx)
|
|
||||||
dy = abs(sy-by)
|
|
||||||
dist = dx+dy
|
|
||||||
y = Y-sy
|
|
||||||
#for x in range(-dist,dist+1):
|
|
||||||
# if abs(x)+abs(y) <= dist:
|
|
||||||
# p = (sx+x, sy+y)
|
|
||||||
# if p != (bx,by):
|
|
||||||
# none.add(sx+x)
|
|
||||||
|
|
||||||
print(len(none))
|
|
||||||
|
|
||||||
objs = []
|
|
||||||
for sx,sy,bx,by in data:
|
|
||||||
dist = abs(sx-bx) + abs(sy-by)
|
|
||||||
objs.append((sx,sy,dist))
|
|
||||||
|
|
||||||
# find the closest sensor to x,y within dist
|
|
||||||
def mindist(x,y, objs=objs):
|
|
||||||
for sx,sy,dist in yobjs:
|
|
||||||
d = abs(x-sx) + abs(y-sy)
|
|
||||||
if d <= dist:
|
|
||||||
yield dist-d
|
|
||||||
|
|
||||||
# y=2573243
|
|
||||||
Y = 2500000
|
|
||||||
Y = 0
|
|
||||||
|
|
||||||
objs.sort()
|
|
||||||
|
|
||||||
for y in range(Y, 4000000+1):
|
|
||||||
ranges = []
|
|
||||||
for sx,sy,dist in objs:
|
|
||||||
dy = abs(y-sy)
|
|
||||||
if dy <= dist:
|
|
||||||
dx = dist - dy
|
|
||||||
ranges.append((sx-dx,sx+dx))
|
|
||||||
ranges.sort()
|
|
||||||
x = 0
|
|
||||||
for a,b in ranges:
|
|
||||||
if b < x:
|
|
||||||
continue
|
|
||||||
if x < a:
|
|
||||||
print(x,y,"=",x*4000000+y)
|
|
||||||
break
|
|
||||||
x = b+1
|
|
||||||
if x > 4000000:
|
|
||||||
break
|
|
||||||
#try:
|
|
||||||
# d = max(mindist(x,y,objs=yobjs))
|
|
||||||
# x += d+1
|
|
||||||
#except ValueError:
|
|
||||||
# print(x,y)
|
|
||||||
# break
|
|
||||||
if y % 100000 == 0:
|
|
||||||
print(y)
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user