commit f0159b7d36e2c81182f2d047a34bf883394894db
parent 19be9f44dbecdde03662be2248eda5b739d67038
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 25 Dec 2024 06:55:22 +0100
Day 25 2024
Diffstat:
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/2024/25/Makefile b/2024/25/Makefile
@@ -0,0 +1,11 @@
+CC=g++ -std=c++20 -g -Wall
+
+a:
+ ${CC} -o a.out day25a.cpp
+ ./a.out
+
+b:
+ ${CC} -o b.out day25b.cpp
+ ./b.out
+
+.PHONY: a b
diff --git a/2024/25/day25a.cpp b/2024/25/day25a.cpp
@@ -0,0 +1,55 @@
+#include <algorithm>
+#include <cstdint>
+#include <iostream>
+#include <map>
+#include <queue>
+#include <ranges>
+#include <set>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <vector>
+using namespace std;
+
+class KeyLock {
+public:
+ KeyLock() { fill(a, a+5, 0); }
+
+ void addrow(const string& s) {
+ for (int i = 0; i < 5; i++)
+ a[i] += s[i] == '#';
+ }
+
+ bool operator&(const KeyLock& other) const {
+ for (int i = 0; i < 5; i++)
+ if (a[i] + other.a[i] > 5)
+ return false;
+ return true;
+ }
+private:
+ int a[5];
+};
+
+int main() {
+ vector<KeyLock> keys, locks;
+ string line;
+ while (getline(cin, line)) {
+ KeyLock k;
+ bool key = line[0] == '.';
+ for (int i = 0; i < 5; i++) {
+ getline(cin, line);
+ k.addrow(line);
+ }
+ if (key) keys.push_back(k);
+ else locks.push_back(k);
+ getline(cin, line);
+ getline(cin, line);
+ }
+
+ int tot = 0;
+ for (auto k : keys)
+ for (auto l : locks)
+ tot += (k & l) ? 1 : 0;
+ cout << tot << endl;
+ return 0;
+}