aboutsummaryrefslogtreecommitdiff
path: root/2024/08/day08a.cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-08 07:49:46 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-08 07:49:46 +0100
commita299e1723f0a700a892720badab2e06a202d1eda (patch)
tree474675a9361b5c7ee805d60972f140fb81380366 /2024/08/day08a.cpp
parentb3231ba7503f551f09b588355dd9f8145282709c (diff)
downloadaoc-a299e1723f0a700a892720badab2e06a202d1eda.tar.gz
aoc-a299e1723f0a700a892720badab2e06a202d1eda.zip
Day 8 2024
Diffstat (limited to '2024/08/day08a.cpp')
-rw-r--r--2024/08/day08a.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/2024/08/day08a.cpp b/2024/08/day08a.cpp
new file mode 100644
index 0000000..7a18ded
--- /dev/null
+++ b/2024/08/day08a.cpp
@@ -0,0 +1,49 @@
1#include <algorithm>
2#include <iostream>
3#include <map>
4#include <set>
5#include <sstream>
6#include <string>
7#include <string_view>
8#include <vector>
9using namespace std;
10
11pair<int, int> antinode(pair<int, int> p, pair<int, int> q) {
12 auto [xp, yp] = p;
13 auto [xq, yq] = q;
14 return make_pair(2*xp-xq, 2*yp-yq);
15}
16
17void add_antinodes(set<pair<int, int>>& points,
18 pair<int, int> p, set<pair<int, int>>& antinodes) {
19 for (auto q : points) {
20 antinodes.insert(antinode(p, q));
21 antinodes.insert(antinode(q, p));
22 }
23}
24
25int main() {
26 string line;
27 map<char, set<pair<int, int>>> d;
28 set<pair<int, int>> antinodes;
29 int i, j;
30 for (i = 0; getline(cin, line); i++) {
31 stringstream s(line);
32 char c;
33 for (j = 0; s >> c; j++) {
34 if (c != '.') {
35 pair<int, int> p(i, j);
36 add_antinodes(d[c], p, antinodes);
37 d[c].insert(p);
38 }
39 }
40 }
41
42 int tot = 0;
43 for (auto [x, y] : antinodes)
44 if (x >= 0 && x < i && y >= 0 && y < j)
45 tot++;
46
47 cout << tot << endl;
48 return 0;
49}

Generated with cgit - Back to sebastiano.tronto.net