diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-23 07:55:11 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-23 07:55:11 +0100 |
| commit | 21e1237e93703f632253f042bd5877998d81c507 (patch) | |
| tree | 671c10254bbc2ed407d8bfa99819460e56c13211 /2024/23/day23a.cpp | |
| parent | cffdd7d528607f7281fc0a1fed9195e711c1b70f (diff) | |
| download | aoc-21e1237e93703f632253f042bd5877998d81c507.tar.gz aoc-21e1237e93703f632253f042bd5877998d81c507.zip | |
Day 23 2024
Diffstat (limited to '2024/23/day23a.cpp')
| -rw-r--r-- | 2024/23/day23a.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/2024/23/day23a.cpp b/2024/23/day23a.cpp new file mode 100644 index 0000000..048a724 --- /dev/null +++ b/2024/23/day23a.cpp | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <cstdint> | ||
| 3 | #include <iostream> | ||
| 4 | #include <map> | ||
| 5 | #include <queue> | ||
| 6 | #include <ranges> | ||
| 7 | #include <set> | ||
| 8 | #include <sstream> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | #include <vector> | ||
| 12 | using namespace std; | ||
| 13 | |||
| 14 | set<int> computers; | ||
| 15 | bool m[26*26][26*26]; | ||
| 16 | |||
| 17 | int index(char a, char b) { return (int)(a-'a') + 26*(int)(b-'a'); } | ||
| 18 | bool t(int i) { return i % 26 == 't' - 'a'; } | ||
| 19 | |||
| 20 | int main() { | ||
| 21 | string line; | ||
| 22 | while (getline(cin, line)) { | ||
| 23 | int i = index(line[0], line[1]); | ||
| 24 | int j = index(line[3], line[4]); | ||
| 25 | computers.insert(i); | ||
| 26 | computers.insert(j); | ||
| 27 | m[i][j] = m[j][i] = true; | ||
| 28 | } | ||
| 29 | |||
| 30 | vector cv(computers.begin(), computers.end()); | ||
| 31 | int tot = 0; | ||
| 32 | for (unsigned i = 0; i < cv.size(); i++) | ||
| 33 | for (unsigned j = i+1; j < cv.size(); j++) | ||
| 34 | for (unsigned k = j+1; k < cv.size(); k++) | ||
| 35 | tot += m[cv[i]][cv[j]] && m[cv[j]][cv[k]] && m[cv[k]][cv[i]] && | ||
| 36 | (t(cv[i]) || t(cv[j]) || t(cv[k])); | ||
| 37 | |||
| 38 | cout << tot << endl; | ||
| 39 | return 0; | ||
| 40 | } | ||
