Skip to content

Commit 3a6bbe0

Browse files
committed
Some clean up
1 parent aa3638c commit 3a6bbe0

32 files changed

Lines changed: 1010 additions & 483 deletions

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ repos:
77
- id: check-yaml
88
- id: check-added-large-files
99

10-
- repo: https://github.com/psf/black
11-
rev: 23.11.0
12-
hooks:
13-
- id: black
14-
1510
- repo: https://github.com/astral-sh/ruff-pre-commit
1611
# Ruff version.
1712
rev: v0.1.6

2024/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# My solutions for Advent of Code 2024
2+
3+
I decided together with some friends to learn [Rust](https://www.rust-lang.org/) with this year's AoC. So all except one task (day 24 task 2) were solved in Rust. For the one task, I ended up using a semi-manual approach using graph plotting (with graphviz). To speed up the plotting process, I decided to resort to python. I might add a rust solution in the futures.
4+
5+
## Solutions
6+
7+
| Day | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 |
8+
| --- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
9+
| Task 01 | [![ferris]](./rust/src/day01.rs) | [![ferris]](./rust/src/day02.rs) | [![ferris]](./rust/src/day03.rs) | [![ferris]](./rust/src/day04.rs) | [![ferris]](./rust/src/day05.rs) | [![ferris]](./rust/src/day06.rs) | [![ferris]](./rust/src/day07.rs) | [![ferris]](./rust/src/day08.rs) | [![ferris]](./rust/src/day09.rs) | [![ferris]](./rust/src/day10.rs) | [![ferris]](./rust/src/day11.rs) | [![ferris]](./rust/src/day12.rs) | [![ferris]](./rust/src/day13.rs) |
10+
| Task 02 | [![ferris]](./rust/src/day01.rs) | [![ferris]](./rust/src/day02.rs) | [![ferris]](./rust/src/day03.rs) | [![ferris]](./rust/src/day04.rs) | [![ferris]](./rust/src/day05.rs) | [![ferris]](./rust/src/day06.rs) | [![ferris]](./rust/src/day07.rs) | [![ferris]](./rust/src/day08.rs) | [![ferris]](./rust/src/day09.rs) | [![ferris]](./rust/src/day10.rs) | [![ferris]](./rust/src/day11.rs) | [![ferris]](./rust/src/day12.rs) | [![ferris]](./rust/src/day13.rs) |
11+
12+
| Day | 14 | 15 | 16 | 17 | 18 | 19 | 20 |21 | 22 | 23 | 24 | 25 |
13+
| --- | -- | -- | -- | -- | -- | -- | -- |-- | -- | -- | -- | -- |
14+
| Task 01 | [![ferris]](./rust/src/day14.rs) | [![ferris]](./rust/src/day15.rs) | [![ferris]](./rust/src/day16.rs) | [![ferris]](./rust/src/day17.rs) | [![ferris]](./rust/src/day18.rs) | [![ferris]](./rust/src/day19.rs) | [![ferris]](./rust/src/day20.rs) | [![ferris]](./rust/src/day21.rs) | [![ferris]](./rust/src/day22.rs) | [![ferris]](./rust/src/day23.rs) | [![ferris]](./rust/src/day24.rs) | [![ferris]](./rust/src/day25.rs) |
15+
| Task 02 | [![ferris]](./rust/src/day14.rs) | [![ferris]](./rust/src/day15.rs) | [![ferris]](./rust/src/day16.rs) | [![ferris]](./rust/src/day17.rs) | [![ferris]](./rust/src/day18.rs) | [![ferris]](./rust/src/day19.rs) | [![ferris]](./rust/src/day20.rs) | [![ferris]](./rust/src/day21.rs) | [![ferris]](./rust/src/day22.rs) | [![ferris]](./rust/src/day23.rs) | [<img src="https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg" width="18"/>](./python/src/aoc2024/day24.py) | :star: |
16+
17+
The ferris icon is licensed under CC0 and can be found [here](https://commons.wikimedia.org/wiki/File:Original_Ferris.svg).
18+
The python icon is licensed under the GPL and can be found [here](https://en.m.wikipedia.org/wiki/File:Python-logo-notext.svg).
19+
20+
## Structure
21+
22+
- [`examples`](./examples) contains the examples as separate files. The file names follow the format `day{day:02d}_{counter:02d}.txt`
23+
- [`inputs`](./inputs) the same for the inputs, but without the counter, i.e., `day{day:02d}.txt`.
24+
- The other directories are named after a programming language and contain the solutions to AoC in that programming language. This year, there is a [`rust`](./rust) and a [`python`](./python) directory. The READMEs in each directory tell you how to run the solutions.
25+
26+
[ferris]: https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg
27+
[python]: https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg

2024/python/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
11
# Solutions for AoC 2024
22

33
This year I wanted to learn rust. So, all except one task were solved in rust only. I took a semi-manual approach for day24 part2 which required to plot a graph using graphviz. The tooling for python seemed easier than the one for rust, so I decided to go for python to speed up the process.
4+
5+
## Setup
6+
7+
Make sure you have [uv](https://docs.astral.sh/uv/getting-started/installation/) installed.
8+
9+
10+
## Run an example
11+
12+
To run an example, you can simply run:
13+
```shell
14+
uv run aoc2024 <day> <task> -e <example_id>
15+
```
16+
For example, if you want to run the first example for day 13 task 2, you would enter
17+
18+
```shell
19+
uv run aoc2024 13 2 -e 1
20+
```
21+
22+
## Run a solution
23+
24+
To run a solution, you can simply leave out the `-e <example_id>`:
25+
```shell
26+
uv run aoc2024 <day> <task>
27+
```
28+
For example, if you want to run the solution for day 16 task 1, you would enter
29+
30+
```shell
31+
uv run aoc2024 16 1
32+
```
33+
34+
## Future directions
35+
36+
1. Adding unittests
37+
2. Adding timing information

2024/rust.code-workspace

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"path": "inputs"
1111
}
1212
],
13-
"settings": {}
14-
}
13+
"settings": {
14+
"editor.formatOnSave": true,
15+
"editor.defaultFormatter": "rust-lang.rust-analyzer"
16+
}
17+
}

2024/rust/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# My solutions for Advent of Code 2024 in Rust
2+
3+
## Setup
4+
5+
Make sure you have [Rust installed](https://www.rust-lang.org/tools/install).
6+
7+
## Run an example
8+
9+
To run an example, you can simply run:
10+
```shell
11+
cargo run -- <day> <task> -e <example_id>
12+
```
13+
The double-dash between `run` and the arguments is important. For example, if you want to run the first example for day 13 task 2, you would enter
14+
15+
```shell
16+
cargo run -- 13 2 -e 1
17+
```
18+
19+
## Run a solution
20+
21+
To run a solution, you can simply leave out the `-e <example_id>`:
22+
```shell
23+
cargo run -- <day> <task>
24+
```
25+
The double-dash between `run` and the arguments is important. For example, if you want to run the solution for day 16 task 1, you would enter
26+
27+
```shell
28+
cargo run -- 16 1
29+
```
30+
31+
## Future directions
32+
33+
1. Adding unittests
34+
2. Adding timing information

2024/rust/src/day01.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ pub fn task02(input: &str) -> String {
5151
}
5252

5353
result.to_string()
54-
}
54+
}

2024/rust/src/day02.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ pub fn task01(input: &str) -> String {
66
continue;
77
}
88

9-
let parts: Vec<i32> = trimmed_line.split(" ").map(|x| x.trim().parse().expect("Should contain integers")).collect();
9+
let parts: Vec<i32> = trimmed_line
10+
.split(" ")
11+
.map(|x| x.trim().parse().expect("Should contain integers"))
12+
.collect();
1013
let mut safe: bool = true;
1114

1215
let mut last = parts[1];
1316
let mut delta = parts[1] - parts[0];
14-
if delta.abs() > 3 || delta == 0 {
15-
continue
17+
if delta.abs() > 3 || delta == 0 {
18+
continue;
1619
}
1720

1821
for i in 2..parts.len() {
1922
let current = parts[i];
2023
let new_delta = current - last;
21-
if new_delta.abs() > 3 || new_delta == 0 || new_delta*delta < 0 {
24+
if new_delta.abs() > 3 || new_delta == 0 || new_delta * delta < 0 {
2225
safe = false;
23-
break
26+
break;
2427
}
2528
delta = new_delta;
2629
last = current;
@@ -41,7 +44,10 @@ pub fn task02(input: &str) -> String {
4144
continue;
4245
}
4346

44-
let parts: Vec<i32> = trimmed_line.split(" ").map(|x| x.trim().parse().expect("Should contain integers")).collect();
47+
let parts: Vec<i32> = trimmed_line
48+
.split(" ")
49+
.map(|x| x.trim().parse().expect("Should contain integers"))
50+
.collect();
4551

4652
for skip in 0..parts.len() {
4753
let mut safe: bool = true;
@@ -55,28 +61,28 @@ pub fn task02(input: &str) -> String {
5561

5662
let mut last = parts[i1];
5763
let mut delta = parts[i1] - parts[i0];
58-
if delta.abs() > 3 || delta == 0 {
59-
continue
64+
if delta.abs() > 3 || delta == 0 {
65+
continue;
6066
}
6167

6268
for i in offset..parts.len() {
6369
if i == skip {
64-
continue
70+
continue;
6571
}
6672
let current = parts[i];
6773
let new_delta = current - last;
68-
if new_delta.abs() > 3 || new_delta == 0 || new_delta*delta < 0 {
74+
if new_delta.abs() > 3 || new_delta == 0 || new_delta * delta < 0 {
6975
safe = false;
70-
break
76+
break;
7177
}
7278
delta = new_delta;
7379
last = current;
7480
}
7581
if safe {
7682
safe_lines += 1;
77-
break
83+
break;
7884
}
7985
}
8086
}
8187
safe_lines.to_string()
82-
}
88+
}

2024/rust/src/day03.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use regex::Regex;
22

33
fn task(input: &str) -> i32 {
44
let re = Regex::new(r"mul\((?<left>\d+),(?<right>\d+)\)").unwrap();
5-
re.captures_iter(input).map(|m| {
6-
let left = m.name("left").unwrap().as_str().parse::<i32>().unwrap();
7-
let right = m.name("right").unwrap().as_str().parse::<i32>().unwrap();
8-
left * right
9-
}).sum()
10-
5+
re.captures_iter(input)
6+
.map(|m| {
7+
let left = m.name("left").unwrap().as_str().parse::<i32>().unwrap();
8+
let right = m.name("right").unwrap().as_str().parse::<i32>().unwrap();
9+
left * right
10+
})
11+
.sum()
1112
}
1213

1314
pub fn task01(input: &str) -> String {
@@ -16,11 +17,11 @@ pub fn task01(input: &str) -> String {
1617
}
1718

1819
pub fn task02(mut input: &str) -> String {
19-
input = input.trim();
20+
input = input.trim();
2021
let mut active = true;
2122

2223
let mut result = 0;
23-
let mut content: &str;
24+
let mut content: &str;
2425
while input.len() != 0 {
2526
if active {
2627
(content, input) = input.split_once("don't()").unwrap_or((input, ""));
@@ -30,7 +31,6 @@ pub fn task02(mut input: &str) -> String {
3031
(_, input) = input.split_once("do()").unwrap_or((input, ""));
3132
active = true
3233
}
33-
3434
}
3535
result.to_string()
36-
}
36+
}

0 commit comments

Comments
 (0)