From 77552dcbbb3281246358b24092c4e51156982ac3 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 13 Dec 2024 06:51:26 +0100 Subject: Day 13 2024 --- 2024/13/day13a.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 2024/13/day13a.cpp (limited to '2024/13/day13a.cpp') diff --git a/2024/13/day13a.cpp b/2024/13/day13a.cpp new file mode 100644 index 0000000..9dccff9 --- /dev/null +++ b/2024/13/day13a.cpp @@ -0,0 +1,62 @@ +/* +This is the dumb solution I wrote before actually thinking how to solve +the problem. Check out day13b.cpp for a better solution (just remove the ++N in the input-reading part). + +Also, both this file and day13b.cpp take a different input format than +what was given. I used clean.sh to convert from 'input-original' to 'input'. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#define INF 999999 + +class Machine { +public: + pair a, b, prize; + + Machine(int a1, int a2, int b1, int b2, int p1, int p2) : + a(a1, a2), b(b1, b2), prize(p1, p2) {} +}; + +int main() { + string line; + int a1, a2, b1, b2, p1, p2; + vector machines; + while (cin >> a1 >> a2) { + cin >> b1 >> b2; + cin >> p1 >> p2; + getline(cin, line); + machines.push_back(Machine(a1, a2, b1, b2, p1, p2)); + } + + int tot = 0; + for (auto m : machines) { + int minp = INF; + for (int i = 0; i <= 100; i++) { + int x = m.prize.first-m.a.first*i; + int y = m.prize.second-m.a.second*i; + if (x % m.b.first != 0 || y % m.b.second != 0) + continue; + int a = x / m.b.first; + int b = y / m.b.second; + if (a != b) + continue; + minp = min(minp, 3*i+a); + } + tot += minp == INF ? 0 : minp; + } + + cout << tot << endl; + + return 0; +} -- cgit v1.3