diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-25 06:55:22 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-25 06:55:36 +0100 |
| commit | f0159b7d36e2c81182f2d047a34bf883394894db (patch) | |
| tree | b9ea6739e1daa28cba39e4abbdd7d455a1584790 /2024/25 | |
| parent | 19be9f44dbecdde03662be2248eda5b739d67038 (diff) | |
| download | aoc-f0159b7d36e2c81182f2d047a34bf883394894db.tar.gz aoc-f0159b7d36e2c81182f2d047a34bf883394894db.zip | |
Day 25 2024
Diffstat (limited to '2024/25')
| -rw-r--r-- | 2024/25/Makefile | 11 | ||||
| -rw-r--r-- | 2024/25/day25a.cpp | 55 |
2 files changed, 66 insertions, 0 deletions
diff --git a/2024/25/Makefile b/2024/25/Makefile new file mode 100644 index 0000000..67dcdd1 --- /dev/null +++ b/2024/25/Makefile | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | CC=g++ -std=c++20 -g -Wall | ||
| 2 | |||
| 3 | a: | ||
| 4 | ${CC} -o a.out day25a.cpp | ||
| 5 | ./a.out | ||
| 6 | |||
| 7 | b: | ||
| 8 | ${CC} -o b.out day25b.cpp | ||
| 9 | ./b.out | ||
| 10 | |||
| 11 | .PHONY: a b | ||
diff --git a/2024/25/day25a.cpp b/2024/25/day25a.cpp new file mode 100644 index 0000000..22d8c15 --- /dev/null +++ b/2024/25/day25a.cpp | |||
| @@ -0,0 +1,55 @@ | |||
| 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 | class KeyLock { | ||
| 15 | public: | ||
| 16 | KeyLock() { fill(a, a+5, 0); } | ||
| 17 | |||
| 18 | void addrow(const string& s) { | ||
| 19 | for (int i = 0; i < 5; i++) | ||
| 20 | a[i] += s[i] == '#'; | ||
| 21 | } | ||
| 22 | |||
| 23 | bool operator&(const KeyLock& other) const { | ||
| 24 | for (int i = 0; i < 5; i++) | ||
| 25 | if (a[i] + other.a[i] > 5) | ||
| 26 | return false; | ||
| 27 | return true; | ||
| 28 | } | ||
| 29 | private: | ||
| 30 | int a[5]; | ||
| 31 | }; | ||
| 32 | |||
| 33 | int main() { | ||
| 34 | vector<KeyLock> keys, locks; | ||
| 35 | string line; | ||
| 36 | while (getline(cin, line)) { | ||
| 37 | KeyLock k; | ||
| 38 | bool key = line[0] == '.'; | ||
| 39 | for (int i = 0; i < 5; i++) { | ||
| 40 | getline(cin, line); | ||
| 41 | k.addrow(line); | ||
| 42 | } | ||
| 43 | if (key) keys.push_back(k); | ||
| 44 | else locks.push_back(k); | ||
| 45 | getline(cin, line); | ||
| 46 | getline(cin, line); | ||
| 47 | } | ||
| 48 | |||
| 49 | int tot = 0; | ||
| 50 | for (auto k : keys) | ||
| 51 | for (auto l : locks) | ||
| 52 | tot += (k & l) ? 1 : 0; | ||
| 53 | cout << tot << endl; | ||
| 54 | return 0; | ||
| 55 | } | ||
