Skip to content

Commit 981a4d0

Browse files
committed
added 2024/day08
1 parent 58869bc commit 981a4d0

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

2024/day08/input.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
........5..................................e..3...
2+
.......q...........m................e.............
3+
....m.......................................e.....
4+
.........................................C........
5+
.u.m........................8.....................
6+
...........7......9.......8...........F...s.......
7+
6...q..............................s..............
8+
..................................................
9+
..................................................
10+
..................................................
11+
..........9....................F..................
12+
.................................M....D...........
13+
.........U........................................
14+
..q................................8..............
15+
.......9..........................................
16+
0....6.....................e..Qs...............F..
17+
.................................Q...D............
18+
.0.u....................................2.........
19+
..................................................
20+
........u................Q........................
21+
.....E........1...................................
22+
...n....v....................................3....
23+
......u..0................N.......................
24+
............................................z.....
25+
.........7....U.........4.....Z...Q.....D.....V...
26+
..............n1.........f.................2......
27+
E.............................f..............z....
28+
...E........1.Z.......U......................D....
29+
.......n...v....7Z...N............................
30+
..........7..N.....Zf...........................3.
31+
................................b............V....
32+
............4..................................9..
33+
..n...v........................5................2.
34+
.........v.................5.........S............
35+
..........................s.......................
36+
.....U.........4..C.....................S..V......
37+
..................................................
38+
......................c........b............M.....
39+
...........4.Wc....d.......1.....b.....S..........
40+
..E........c............................5......z..
41+
..............w..C....................SM.2........
42+
........................d.........................
43+
...............c......C3..........................
44+
...............w....W.............................
45+
..................................................
46+
.........d.......B....w...........................
47+
....B.....W.......dw..........................M...
48+
...............W......................N...V.......
49+
.B................................................
50+
....................B...............b.............

2024/day08/run.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#! /usr/bin/env python3
2+
3+
a = { x+1j*y: c for y, line in enumerate(open('input.txt').read().splitlines()) for x, c in enumerate(line) }
4+
g = lambda c: a.get(c, "")
5+
6+
# Part One
7+
8+
from itertools import combinations
9+
10+
all_antennas = set(a.values()) - set(['.'])
11+
12+
def all_pairs():
13+
for antenna in all_antennas:
14+
coords = [ key for key, value in a.items() if value == antenna ]
15+
for n, m in combinations(coords, 2):
16+
yield m, n
17+
18+
antidots = set()
19+
20+
for m, n in all_pairs():
21+
d = m - n
22+
if g(n - d) != '':
23+
antidots.add(n - d)
24+
if g(m + d) != '':
25+
antidots.add(m + d)
26+
27+
print(len(antidots))
28+
29+
# Part Two
30+
31+
antidots = set()
32+
33+
for m, n in all_pairs():
34+
d = m - n
35+
antidots |= set( m + k*d for k in range(-100, 100) if g(m + k*d) != '' )
36+
37+
print(len(antidots))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
2021 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +
1010
2022 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- ++ ++ ++ ++ ++ +
1111
2023 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ ++ ++ ++ ++ ++ +
12-
2024 ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
12+
2024 ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
1313
```

0 commit comments

Comments
 (0)