From f0159b7d36e2c81182f2d047a34bf883394894db Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 25 Dec 2024 06:55:22 +0100 Subject: Day 25 2024 --- 2024/25/Makefile | 11 +++++++++++ 2024/25/day25a.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 2024/25/Makefile create mode 100644 2024/25/day25a.cpp 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 @@ +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 new file mode 100644 index 0000000..22d8c15 --- /dev/null +++ b/2024/25/day25a.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +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 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; +} -- cgit v1.3