2024 day 8

This commit is contained in:
eriedaberrie 2024-12-07 21:52:31 -08:00
parent a311e1d88a
commit ce3dc4f81a
2 changed files with 96 additions and 0 deletions

46
2024/8/main-1.cpp Normal file
View file

@ -0,0 +1,46 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
map<char, vector<pair<int, int>>> nodes;
string line;
vector<string> lines;
while (getline(cin, line) && !line.empty()) {
lines.push_back(line);
}
int mx = lines.size(), my = lines[0].size();
for (int x = 0; x < mx; x++) {
for (int y = 0; y < my; y++) {
char c = lines[x][y];
if (c != '.') {
nodes[c].push_back({x, y});
}
}
}
set<pair<int, int>> total;
for (auto &[c, poss] : nodes) {
for (int a = 1; a < poss.size(); a++) {
for (int b = 0; b < a; b++) {
vector<pair<int, int>> pos = {
{poss[b].first * 2 - poss[a].first,
poss[b].second * 2 - poss[a].second},
{poss[a].first * 2 - poss[b].first,
poss[a].second * 2 - poss[b].second}};
for (auto &x : pos) {
if (x.first >= 0 && x.first < mx && x.second >= 0 &&
x.second < my) {
total.insert(x);
}
}
}
}
}
cout << total.size() << '\n';
}

50
2024/8/main-2.cpp Normal file
View file

@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
map<char, vector<pair<int, int>>> nodes;
string line;
vector<string> lines;
while (getline(cin, line) && !line.empty()) {
lines.push_back(line);
}
int mx = lines.size(), my = lines[0].size();
for (int x = 0; x < mx; x++) {
for (int y = 0; y < my; y++) {
char c = lines[x][y];
if (c != '.') {
nodes[c].push_back({x, y});
}
}
}
set<pair<int, int>> total;
for (auto &[c, poss] : nodes) {
for (int a = 1; a < poss.size(); a++) {
for (int b = 0; b < a; b++) {
int dx = poss[a].first - poss[b].first;
int dy = poss[a].second - poss[b].second;
int x = poss[a].first, y = poss[a].second;
while (x >= 0 && x < mx && y >= 0 && y < my) {
x -= dx;
y -= dy;
}
for (;;) {
x += dx;
y += dy;
if (!(x >= 0 && x < mx && y >= 0 && y < my)) {
break;
}
total.insert({x, y});
}
}
}
}
cout << total.size() << '\n';
}