From a299e1723f0a700a892720badab2e06a202d1eda Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 8 Dec 2024 07:49:46 +0100 Subject: Day 8 2024 --- 2024/08/day08a.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 2024/08/day08a.cpp (limited to '2024/08/day08a.cpp') 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 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +pair antinode(pair p, pair q) { + auto [xp, yp] = p; + auto [xq, yq] = q; + return make_pair(2*xp-xq, 2*yp-yq); +} + +void add_antinodes(set>& points, + pair p, set>& antinodes) { + for (auto q : points) { + antinodes.insert(antinode(p, q)); + antinodes.insert(antinode(q, p)); + } +} + +int main() { + string line; + map>> d; + set> antinodes; + int i, j; + for (i = 0; getline(cin, line); i++) { + stringstream s(line); + char c; + for (j = 0; s >> c; j++) { + if (c != '.') { + pair p(i, j); + add_antinodes(d[c], p, antinodes); + d[c].insert(p); + } + } + } + + int tot = 0; + for (auto [x, y] : antinodes) + if (x >= 0 && x < i && y >= 0 && y < j) + tot++; + + cout << tot << endl; + return 0; +} -- cgit v1.3