aboutsummaryrefslogtreecommitdiff
path: root/2024/01
diff options
context:
space:
mode:
Diffstat (limited to '2024/01')
-rw-r--r--2024/01/Makefile24
-rwxr-xr-x2024/01/b.outbin0 -> 78536 bytes
-rw-r--r--2024/01/day01a.cpp24
-rw-r--r--2024/01/day01b.cpp21
4 files changed, 69 insertions, 0 deletions
diff --git a/2024/01/Makefile b/2024/01/Makefile
new file mode 100644
index 0000000..706085c
--- /dev/null
+++ b/2024/01/Makefile
@@ -0,0 +1,24 @@
1CC=g++ -std=c++20 -g -Wall
2
3a:
4 ${CC} -o a.out day01a.cpp
5
6b:
7 ${CC} -o b.out day01b.cpp
8
9clean:
10 rm -f a b
11
12atest: a
13 ./a.out
14
15btest: b
16 ./b.out
17
18arun: a
19 ./a.out < input
20
21brun: b
22 ./b.out < input
23
24.PHONY: a b clean atest btest arun brun
diff --git a/2024/01/b.out b/2024/01/b.out
new file mode 100755
index 0000000..3b75578
--- /dev/null
+++ b/2024/01/b.out
Binary files differ
diff --git a/2024/01/day01a.cpp b/2024/01/day01a.cpp
new file mode 100644
index 0000000..e4a61e0
--- /dev/null
+++ b/2024/01/day01a.cpp
@@ -0,0 +1,24 @@
1#include <iostream>
2#include <algorithm>
3#include <vector>
4using namespace std;
5
6int main() {
7 int x, y, tot;
8 vector<int> v, w;
9
10 while (cin >> x >> y) {
11 v.push_back(x);
12 w.push_back(y);
13 }
14
15 sort(v.begin(), v.end());
16 sort(w.begin(), w.end());
17
18 tot = 0;
19 for (unsigned i = 0; i < v.size(); i++)
20 tot += abs(v[i] - w[i]);
21
22 cout << tot << endl;
23 return 0;
24}
diff --git a/2024/01/day01b.cpp b/2024/01/day01b.cpp
new file mode 100644
index 0000000..91ef0db
--- /dev/null
+++ b/2024/01/day01b.cpp
@@ -0,0 +1,21 @@
1#include <iostream>
2#include <algorithm>
3#include <vector>
4using namespace std;
5
6int main() {
7 int x, y, tot;
8 vector<int> v, w;
9
10 while (cin >> x >> y) {
11 v.push_back(x);
12 w.push_back(y);
13 }
14
15 tot = 0;
16 for (unsigned i = 0; i < v.size(); i++)
17 tot += v[i] * count(w.begin(), w.end(), v[i]);
18
19 cout << tot << endl;
20 return 0;
21}

Generated with cgit - Back to sebastiano.tronto.net