aboutsummaryrefslogtreecommitdiff
path: root/2024/13/day13a.cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-13 06:51:26 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-13 06:51:26 +0100
commit77552dcbbb3281246358b24092c4e51156982ac3 (patch)
treeb7b784580345f10693b6dcf398298130854bec37 /2024/13/day13a.cpp
parent3418444a8da97e5a05f87f9737bed94edd43ec60 (diff)
downloadaoc-77552dcbbb3281246358b24092c4e51156982ac3.tar.gz
aoc-77552dcbbb3281246358b24092c4e51156982ac3.zip
Day 13 2024
Diffstat (limited to '2024/13/day13a.cpp')
-rw-r--r--2024/13/day13a.cpp62
1 files changed, 62 insertions, 0 deletions
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 @@
1/*
2This is the dumb solution I wrote before actually thinking how to solve
3the problem. Check out day13b.cpp for a better solution (just remove the
4+N in the input-reading part).
5
6Also, both this file and day13b.cpp take a different input format than
7what was given. I used clean.sh to convert from 'input-original' to 'input'.
8*/
9
10#include <algorithm>
11#include <iostream>
12#include <map>
13#include <ranges>
14#include <set>
15#include <sstream>
16#include <string>
17#include <string_view>
18#include <vector>
19using namespace std;
20
21#define INF 999999
22
23class Machine {
24public:
25 pair<int, int> a, b, prize;
26
27 Machine(int a1, int a2, int b1, int b2, int p1, int p2) :
28 a(a1, a2), b(b1, b2), prize(p1, p2) {}
29};
30
31int main() {
32 string line;
33 int a1, a2, b1, b2, p1, p2;
34 vector <Machine> machines;
35 while (cin >> a1 >> a2) {
36 cin >> b1 >> b2;
37 cin >> p1 >> p2;
38 getline(cin, line);
39 machines.push_back(Machine(a1, a2, b1, b2, p1, p2));
40 }
41
42 int tot = 0;
43 for (auto m : machines) {
44 int minp = INF;
45 for (int i = 0; i <= 100; i++) {
46 int x = m.prize.first-m.a.first*i;
47 int y = m.prize.second-m.a.second*i;
48 if (x % m.b.first != 0 || y % m.b.second != 0)
49 continue;
50 int a = x / m.b.first;
51 int b = y / m.b.second;
52 if (a != b)
53 continue;
54 minp = min(minp, 3*i+a);
55 }
56 tot += minp == INF ? 0 : minp;
57 }
58
59 cout << tot << endl;
60
61 return 0;
62}

Generated with cgit - Back to sebastiano.tronto.net