main
magical 2024-12-08 05:20:33 +00:00
parent 7373859412
commit 7e2e395314
7 changed files with 172 additions and 0 deletions

50
day08/input 100644
View File

@ -0,0 +1,50 @@
.AU..Z.....8.......................t..C.6.........
..................................................
.....K.U....................v.....................
...Z..A.............................v8.....t......
p..................a8...........b...t.............
..pU.....A..4.....................................
..........................E.......................
...........K..V..............v8.....Cb............
....V................b...p........................
....7.............................................
....4.....A..........V......K..E.....6............
.4.........................Vb...........0..C......
..................................k........N......
K....7...........9...........6.....kE.............
......7......1...................k.......C........
...p....................9....0.....N6.............
..........Z........e..1...........................
.............................E................N...
...4...............................v0..........z..
........U.....Z......1................z..a........
.....5.......7......................N.............
....................n.............................
.......................0.9...c..........z.d.T.....
...................n.W......a...t......D....d.....
..........I.....e......................o9.........
....5..2................e...........D.............
...........................n......D...............
......25I...1..................c......W.......o...
................n..............D..................
...........I........i..e..........................
......5......2.....P..............a...............
...........................z..................T...
..........j.....................Wd...........O..o.
................................................c.
.................I................B...............
...........u.............................T.d......
.............................................J....
.....3.i....u......................o..............
3...i.............................................
..................................................
...........j...............W....O............w....
...P........................J.....................
.....u............................................
.............................w....................
......u.................2...w...J.................
.....j.....B3......................O..............
P....B..............................c.............
................B.............w...................
.....i.............3..............................
..P.j....................J..........O.............

12
day08/sample1.in 100644
View File

@ -0,0 +1,12 @@
............
........0...
.....0......
.......0....
....0.......
......A.....
............
............
........A...
.........A..
............
............

10
day08/sample2.in 100644
View File

@ -0,0 +1,10 @@
..........
...#......
..........
....a.....
..........
.....a....
..........
......#...
..........
..........

10
day08/sample3.in 100644
View File

@ -0,0 +1,10 @@
..........
...#......
#.........
....a.....
........a.
.....a....
..#.......
......#...
..........
..........

10
day08/sample4.in 100644
View File

@ -0,0 +1,10 @@
..........
...#......
#.........
....a.....
........a.
.....a....
..#.......
......A...
..........
..........

12
day08/sample5.in 100644
View File

@ -0,0 +1,12 @@
......#....#
...#....0...
....#0....#.
..#....0....
....0....#..
.#....A.....
...#........
#......#....
........A...
.........A..
..........#.
..........#.

68
day08/sol.py 100644
View File

@ -0,0 +1,68 @@
def parse(file):
grid = []
for line in file:
grid.append(line.strip())
return grid
import itertools
import string
signal_chars = string.ascii_letters + string.digits
def solve(file):
grid = parse(file)
ny = len(grid)
nx = len(grid[0])
antennae = {}
for y in range(ny):
for x in range(nx):
c = grid[y][x]
if c in signal_chars:
antennae.setdefault(c, []).append((x,y))
poles = set()
for c, locations in antennae.items():
for (x0,y0), (x1,y1) in itertools.combinations(locations, 2):
x = x1 + (x1-x0)
y = y1 + (y1-y0)
#print(c, (x0,y0),(x1,y1), "=>", (x,y))
if 0 <= x < nx and 0 <= y < ny:
poles.add((x,y))
x = x0 + (x0-x1)
y = y0 + (y0-y1)
if 0 <= x < nx and 0 <= y < ny:
poles.add((x,y))
#for y,line in enumerate(grid):
# print("".join(c if (x,y) not in poles else '#' for (x,c) in enumerate(line)))
print(len(poles))
poles = set()
for c, locations in antennae.items():
for (x0,y0), (x1,y1) in itertools.combinations(locations, 2):
for _ in 1,2:
dx = (x1-x0)
dy = (y1-y0)
x = x1
y = y1
while 0 <= x < nx and 0 <= y < ny:
#print(c, (x0,y0),(x1,y1), "=>", (x,y))
poles.add((x,y))
x += dx
y += dy
x0,y0, x1,y1 = x1,y1, x0,y0
#for y,line in enumerate(grid):
# print("".join(c if (x,y) not in poles else '#' for (x,c) in enumerate(line)))
print(len(poles))
solve(open("sample1.in"))
solve(open("input"))