aboutsummaryrefslogtreecommitdiff
path: root/2024/08
diff options
context:
space:
mode:
Diffstat (limited to '2024/08')
-rw-r--r--2024/08/.gitignore1
-rw-r--r--2024/08/Makefile1
-rw-r--r--2024/08/input50
-rw-r--r--2024/08/puzzles.py40
4 files changed, 92 insertions, 0 deletions
diff --git a/2024/08/.gitignore b/2024/08/.gitignore
new file mode 100644
index 0000000..8931d44
--- /dev/null
+++ b/2024/08/.gitignore
@@ -0,0 +1 @@
+puzzle-[12].py \ No newline at end of file
diff --git a/2024/08/Makefile b/2024/08/Makefile
new file mode 100644
index 0000000..6e58a9d
--- /dev/null
+++ b/2024/08/Makefile
@@ -0,0 +1 @@
+include ../../Makefiles/py.mk \ No newline at end of file
diff --git a/2024/08/input b/2024/08/input
new file mode 100644
index 0000000..3b9068b
--- /dev/null
+++ b/2024/08/input
@@ -0,0 +1,50 @@
+..................................3.........H.....
+..............F............................CK.....
+..................F...e...m..........C.Ki.........
+......1..................m........................
+.........F.1......................................
+.......1.....W...........3..Z............i........
+...........W...m....1.............................
+......W...........m..............N..C.............
+E............2................Z.K.......p.........
+.....Y.........4....i.........N...................
+..............W.Y....................3..9....i....
+.................................h........9.......
+.........................................Z.......H
+2...............................3.......H9........
+..2..........4T...................................
+...2..............Y...4........Z..................
+.........E.........................N...5..........
+.......................................e..........
+..............................C...................
+..E..................P.....................p.H....
+......4............................IN......h.p....
+..........................T....M.........K..p.....
+..........................G.......................
+..................................................
+...................................M..............
+.5.............G..............M...................
+.............Y..........................M.........
+.................E8...0.........................h.
+.............................P............g.......
+......5...........................................
+.............n.................................c..
+...............................g....f.......c.....
+.y..............8...t....T........................
+..7..F.............T........R..........f........u.
+.kz.......7..R....................................
+.........8..................U.........P...........
+......U.............wG....v.....P.............c...
+...0.....R..........g.............................
+.....7.....8.........g.............f..............
+....z...........G................7................
+........5........6.v.....U..f.......u........e....
+.........V....v........6......t...................
+......6..0..y.....R........V...........r..........
+...........v.......we..U.............c..r.........
+................................r.......Iu........
+k............y6..........t.................r...I..
+........k............t...........w................
+.............z....n.................I.............
+..0.................n.............................
+...............n..........V...........y........u.. \ No newline at end of file
diff --git a/2024/08/puzzles.py b/2024/08/puzzles.py
new file mode 100644
index 0000000..87c4c46
--- /dev/null
+++ b/2024/08/puzzles.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python3
+
+import collections
+import itertools
+
+
+type Antennas = defaultdict[str, list[complex]]
+
+
+def main() -> None:
+ with open("input", "r") as f:
+ data = [x.rstrip() for x in f.readlines()]
+ w, h = len(data[0]), len(data)
+
+ antennas: Antennas = collections.defaultdict(list)
+ antinodes: set[complex] = set()
+
+ for y, row in enumerate(data):
+ for x, ch in enumerate(row):
+ if ch != '.':
+ antennas[ch].append(complex(x, y))
+
+ for coords in antennas.values():
+ for a, b in itertools.combinations(coords, 2):
+ v⃗ = a - b
+ u⃗ = b - a
+ # START PART 1
+ antinodes.add(a + u⃗*2)
+ antinodes.add(b + v⃗*2)
+ # END PART 1 START PART 2
+ for i in range(1, max(w, h)):
+ antinodes.add(a + u⃗*i)
+ antinodes.add(b + v⃗*i)
+ # END PART 2
+
+ print(sum(0 <= x.real < w and 0 <= x.imag < h for x in antinodes))
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file