day 15 python part 1

main
magical 2022-12-14 21:26:18 -08:00
parent 37e5ab92e0
commit af21ad12cc
3 changed files with 61 additions and 0 deletions

23
day15/input 100644
View File

@ -0,0 +1,23 @@
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 100644
View File

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

24
day15/sol.py 100644
View File

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