aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-01 09:40:19 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-01 09:40:19 +0100
commit0aefd410a18acf826af5187cdb038fd9b4f25fc5 (patch)
treef24d69d83567079412924bf6ce06e058673171b7 /2024
parent6c5fe99d41a3d63975deb08911ebb0e162684a43 (diff)
downloadaoc-0aefd410a18acf826af5187cdb038fd9b4f25fc5.tar.gz
aoc-0aefd410a18acf826af5187cdb038fd9b4f25fc5.zip
Started 2024 + day 1
Diffstat (limited to '2024')
-rw-r--r--2024/.gitignore2
-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
-rw-r--r--2024/README.md41
-rwxr-xr-x2024/init.sh7
-rw-r--r--2024/learned.txt3
-rw-r--r--2024/template.cpp10
-rw-r--r--2024/template.make24
10 files changed, 156 insertions, 0 deletions
diff --git a/2024/.gitignore b/2024/.gitignore
new file mode 100644
index 0000000..46d4a8d
--- /dev/null
+++ b/2024/.gitignore
@@ -0,0 +1,2 @@
1*/a
2*/b
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}
diff --git a/2024/README.md b/2024/README.md
new file mode 100644
index 0000000..4f2580b
--- /dev/null
+++ b/2024/README.md
@@ -0,0 +1,41 @@
1# Advent of Code 2024
2
3This is my second year trying the AoC. This time I decided to take this
4as an excuse to improve my C++ skills, so I'll use that instead of C.
5
6As last year, my solutions are not commented, but feel free to send
7me an email at sebastiano@tronto.net if you want to know how I solved
8each problem!
9
10## Template
11
12This time I am trying to use a decent template for each day. Here are the
13instructions in case you want to use it.
14
15To start a new day run
16
17```
18$ ./init N
19```
20
21For example, to start day 7 you should run:
22
23```
24$ ./init.sh 7
25```
26
27and the script is going to create a folder `07` and copy some template
28files there. Then you can copy the `input` file into that folder, edit
29`dayNNa.cpp` and once your code is ready you can run
30
31```
32$ make arun
33```
34
35To run the first part with the downloaded input file. You can also use
36`make atest` to take the input from standard input, so you can copy-paste
37the test case into your terminal; press Ctrl-D to enter and EOF and
38terminate the input.
39
40For second part you can edit the file `dayNNb.cpp` and run `make btest`
41and `make brun`.
diff --git a/2024/init.sh b/2024/init.sh
new file mode 100755
index 0000000..1028c3a
--- /dev/null
+++ b/2024/init.sh
@@ -0,0 +1,7 @@
1#!/bin/sh
2
3nn="$(printf '%02d' $1)"
4mkdir -p $nn
5sed "s/DAY/$nn/g" template.make > $nn/Makefile
6cp template.cpp $nn/day${nn}a.cpp
7cp template.cpp $nn/day${nn}b.cpp
diff --git a/2024/learned.txt b/2024/learned.txt
new file mode 100644
index 0000000..56101dd
--- /dev/null
+++ b/2024/learned.txt
@@ -0,0 +1,3 @@
1List of things I learned (or refreshed) with this year's AoC.
2
3* Day 1: std::count()
diff --git a/2024/template.cpp b/2024/template.cpp
new file mode 100644
index 0000000..8428266
--- /dev/null
+++ b/2024/template.cpp
@@ -0,0 +1,10 @@
1#include <iostream>
2#include <vector>
3#include <algorithm>
4using namespace std;
5
6int main() {
7 while (cin >> TODO)
8 ;
9 return 0;
10}
diff --git a/2024/template.make b/2024/template.make
new file mode 100644
index 0000000..4499650
--- /dev/null
+++ b/2024/template.make
@@ -0,0 +1,24 @@
1CC=g++ -std=c++20 -g -Wall
2
3a:
4 ${CC} -o a.out dayDAYa.cpp
5
6b:
7 ${CC} -o b.out dayDAYb.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

Generated with cgit - Back to sebastiano.tronto.net