diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-01 09:40:19 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-01 09:40:19 +0100 |
| commit | 0aefd410a18acf826af5187cdb038fd9b4f25fc5 (patch) | |
| tree | f24d69d83567079412924bf6ce06e058673171b7 /2024 | |
| parent | 6c5fe99d41a3d63975deb08911ebb0e162684a43 (diff) | |
| download | aoc-0aefd410a18acf826af5187cdb038fd9b4f25fc5.tar.gz aoc-0aefd410a18acf826af5187cdb038fd9b4f25fc5.zip | |
Started 2024 + day 1
Diffstat (limited to '2024')
| -rw-r--r-- | 2024/.gitignore | 2 | ||||
| -rw-r--r-- | 2024/01/Makefile | 24 | ||||
| -rwxr-xr-x | 2024/01/b.out | bin | 0 -> 78536 bytes | |||
| -rw-r--r-- | 2024/01/day01a.cpp | 24 | ||||
| -rw-r--r-- | 2024/01/day01b.cpp | 21 | ||||
| -rw-r--r-- | 2024/README.md | 41 | ||||
| -rwxr-xr-x | 2024/init.sh | 7 | ||||
| -rw-r--r-- | 2024/learned.txt | 3 | ||||
| -rw-r--r-- | 2024/template.cpp | 10 | ||||
| -rw-r--r-- | 2024/template.make | 24 |
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 @@ | |||
| 1 | CC=g++ -std=c++20 -g -Wall | ||
| 2 | |||
| 3 | a: | ||
| 4 | ${CC} -o a.out day01a.cpp | ||
| 5 | |||
| 6 | b: | ||
| 7 | ${CC} -o b.out day01b.cpp | ||
| 8 | |||
| 9 | clean: | ||
| 10 | rm -f a b | ||
| 11 | |||
| 12 | atest: a | ||
| 13 | ./a.out | ||
| 14 | |||
| 15 | btest: b | ||
| 16 | ./b.out | ||
| 17 | |||
| 18 | arun: a | ||
| 19 | ./a.out < input | ||
| 20 | |||
| 21 | brun: 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> | ||
| 4 | using namespace std; | ||
| 5 | |||
| 6 | int 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> | ||
| 4 | using namespace std; | ||
| 5 | |||
| 6 | int 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 | |||
| 3 | This is my second year trying the AoC. This time I decided to take this | ||
| 4 | as an excuse to improve my C++ skills, so I'll use that instead of C. | ||
| 5 | |||
| 6 | As last year, my solutions are not commented, but feel free to send | ||
| 7 | me an email at sebastiano@tronto.net if you want to know how I solved | ||
| 8 | each problem! | ||
| 9 | |||
| 10 | ## Template | ||
| 11 | |||
| 12 | This time I am trying to use a decent template for each day. Here are the | ||
| 13 | instructions in case you want to use it. | ||
| 14 | |||
| 15 | To start a new day run | ||
| 16 | |||
| 17 | ``` | ||
| 18 | $ ./init N | ||
| 19 | ``` | ||
| 20 | |||
| 21 | For example, to start day 7 you should run: | ||
| 22 | |||
| 23 | ``` | ||
| 24 | $ ./init.sh 7 | ||
| 25 | ``` | ||
| 26 | |||
| 27 | and the script is going to create a folder `07` and copy some template | ||
| 28 | files 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 | |||
| 35 | To 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 | ||
| 37 | the test case into your terminal; press Ctrl-D to enter and EOF and | ||
| 38 | terminate the input. | ||
| 39 | |||
| 40 | For second part you can edit the file `dayNNb.cpp` and run `make btest` | ||
| 41 | and `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 | |||
| 3 | nn="$(printf '%02d' $1)" | ||
| 4 | mkdir -p $nn | ||
| 5 | sed "s/DAY/$nn/g" template.make > $nn/Makefile | ||
| 6 | cp template.cpp $nn/day${nn}a.cpp | ||
| 7 | cp 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 @@ | |||
| 1 | List 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> | ||
| 4 | using namespace std; | ||
| 5 | |||
| 6 | int 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 @@ | |||
| 1 | CC=g++ -std=c++20 -g -Wall | ||
| 2 | |||
| 3 | a: | ||
| 4 | ${CC} -o a.out dayDAYa.cpp | ||
| 5 | |||
| 6 | b: | ||
| 7 | ${CC} -o b.out dayDAYb.cpp | ||
| 8 | |||
| 9 | clean: | ||
| 10 | rm -f a b | ||
| 11 | |||
| 12 | atest: a | ||
| 13 | ./a.out | ||
| 14 | |||
| 15 | btest: b | ||
| 16 | ./b.out | ||
| 17 | |||
| 18 | arun: a | ||
| 19 | ./a.out < input | ||
| 20 | |||
| 21 | brun: b | ||
| 22 | ./b.out < input | ||
| 23 | |||
| 24 | .PHONY: a b clean atest btest arun brun | ||
