summaryrefslogtreecommitdiff
path: root/2024/day08
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-12-11 10:18:23 +0100
committerBotond Hende <nettingman@gmail.com>2024-12-11 10:18:23 +0100
commit0a5c1f77d01fc0bd166494787f24562e2fd3a9e9 (patch)
tree99b0d38ef86653b6ff4aae26381ebdf0895f829d /2024/day08
parentcbf5c348db4a693b15e455a23e07072587edf4b0 (diff)
renamed day folders to two digit format
Diffstat (limited to '2024/day08')
-rw-r--r--2024/day08/input50
-rw-r--r--2024/day08/input_test12
-rw-r--r--2024/day08/solve.py34
-rw-r--r--2024/day08/solve2.py35
4 files changed, 131 insertions, 0 deletions
diff --git a/2024/day08/input b/2024/day08/input
new file mode 100644
index 0000000..8f67508
--- /dev/null
+++ b/2024/day08/input
@@ -0,0 +1,50 @@
+..F..........L............5.......................
+............................L.U...................
+..................................................
+.............z.L.........5.....4........8....1.P..
+...F................D..4.8.............P......J...
+......f................8....z........U..J.........
+.......D..f........B..o.........m..........JX.....
+......o...5........F..........m.......6....X......
+....s........f...n.....54.U....E................3.
+....F.......l.......k..............6.3n...........
+L..........z....7..U............E...k.P..3b.......
+..s.......D..........h...k.....G........y..m......
+d..............o.........X............8...n.......
+...........o.......D.......J......................
+....................z.....1.9....G6..Y.b....y.....
+.d................4.........EN..G.9.b.............
+.......................7..........................
+..d................l.........pc..n................
+..............l........1Nm..........G..9..........
+.f.........s...7........1........E........X....y..
+.............d...................6......v.........
+........................h.............B...........
+.......l.......................h........B.....p..y
+........w......A................................M.
+.....s.................O...........p.......2......
+...............9.........................B.b......
+......................w..0..............H.........
+.....................w7.j..O....................e.
+.A......Z...................K...h...M.............
+.................S....KZ..........................
+.................V..............x.................
+......Z...............................N...........
+.......................a..........................
+....A..........................K.................M
+.......Z..................ON.KT.........c.........
+...........................YO....t.......x........
+..............g........w.T.............k...c......
+..........................v.......................
+....S..................................u..........
+..........0............v...............c...e..C.p.
+.......S............V.j........v.......x..........
+......S..0W.......HT....a.........................
+A..............H...W..a......C....................
+................T.2.....V......H..t...u........C..
+.................g.j....2.........u..t...e......C.
+.........W...........g.......................u....
+........W...0.................Y.........e.tM......
+................g..a.j............................
+..................................................
+.................2........Y...........x........... \ No newline at end of file
diff --git a/2024/day08/input_test b/2024/day08/input_test
new file mode 100644
index 0000000..de0f909
--- /dev/null
+++ b/2024/day08/input_test
@@ -0,0 +1,12 @@
+............
+........0...
+.....0......
+.......0....
+....0.......
+......A.....
+............
+............
+........A...
+.........A..
+............
+............ \ No newline at end of file
diff --git a/2024/day08/solve.py b/2024/day08/solve.py
new file mode 100644
index 0000000..9dba99e
--- /dev/null
+++ b/2024/day08/solve.py
@@ -0,0 +1,34 @@
+lines = []
+
+with open("input") as f:
+ for line in f:
+ lines.append(line.strip())
+
+antennas: dict[str, list[tuple[int, int]]] = {}
+for row_idx, line in enumerate(lines):
+ for col_idx, char in enumerate(line):
+ if char != ".":
+ if char not in antennas:
+ antennas[char] = []
+
+ antennas[char].append((row_idx, col_idx))
+
+row_count = len(lines)
+col_count = len(lines[0])
+antinodes: set[tuple[int, int]] = set()
+for antenna_list in antennas.values():
+ for idx, antenna1 in enumerate(antenna_list):
+ for antenna2 in antenna_list[idx + 1:]:
+ row_diff = antenna2[0] - antenna1[0]
+ col_diff = antenna2[1] - antenna1[1]
+
+ pos1 = (antenna1[0] - row_diff, antenna1[1] - col_diff)
+ pos2 = (antenna2[0] + row_diff, antenna2[1] + col_diff)
+
+ if 0 <= pos1[0] < row_count and 0 <= pos1[1] < col_count:
+ antinodes.add(pos1)
+
+ if 0 <= pos2[0] < row_count and 0 <= pos2[1] < col_count:
+ antinodes.add(pos2)
+
+print(len(antinodes)) \ No newline at end of file
diff --git a/2024/day08/solve2.py b/2024/day08/solve2.py
new file mode 100644
index 0000000..1642e35
--- /dev/null
+++ b/2024/day08/solve2.py
@@ -0,0 +1,35 @@
+lines = []
+
+with open("input") as f:
+ for line in f:
+ lines.append(line.strip())
+
+antennas: dict[str, list[tuple[int, int]]] = {}
+for row_idx, line in enumerate(lines):
+ for col_idx, char in enumerate(line):
+ if char != ".":
+ if char not in antennas:
+ antennas[char] = []
+
+ antennas[char].append((row_idx, col_idx))
+
+row_count = len(lines)
+col_count = len(lines[0])
+antinodes: set[tuple[int, int]] = set()
+for antenna_list in antennas.values():
+ for idx, antenna1 in enumerate(antenna_list):
+ for antenna2 in antenna_list[idx + 1:]:
+ row_diff = antenna2[0] - antenna1[0]
+ col_diff = antenna2[1] - antenna1[1]
+
+ pos = antenna1
+ while 0 <= pos[0] < row_count and 0 <= pos[1] < col_count:
+ antinodes.add(pos)
+ pos = (pos[0] - row_diff, pos[1] - col_diff)
+
+ pos = antenna2
+ while 0 <= pos[0] < row_count and 0 <= pos[1] < col_count:
+ antinodes.add(pos)
+ pos = (pos[0] + row_diff, pos[1] + col_diff)
+
+print(len(antinodes)) \ No newline at end of file