Skip to content

Commit 6217eec

Browse files
committed
Updates and cleaning
1 parent c1aea0e commit 6217eec

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ Solutions for [Advent of Code](https://adventofcode.com/2024) in [Rust](https://
1111

1212
| Day | Part 1 | Part 2 |
1313
| :---: | :---: | :---: |
14-
| [Day 1](./src/bin/01.rs) | `67.1µs` | `86.5µs` |
15-
| [Day 2](./src/bin/02.rs) | `122.0µs` | `236.9µs` |
16-
| [Day 3](./src/bin/03.rs) | `256.4µs` | `294.9µs` |
17-
| [Day 4](./src/bin/04.rs) | `257.6µs` | `81.1µs` |
18-
| [Day 5](./src/bin/05.rs) | `186.0µs` | `259.8µs` |
19-
| [Day 6](./src/bin/06.rs) | `155.6µs` | `177.2ms` |
20-
| [Day 7](./src/bin/07.rs) | `1.1ms` | `331.9ms` |
21-
| [Day 8](./src/bin/08.rs) | `70.5µs` | `52.7µs` |
22-
| [Day 9](./src/bin/09.rs) | `110.8µs` | `536.0ms` |
23-
| [Day 10](./src/bin/10.rs) | `142.9µs` | `81.9µs` |
24-
| [Day 11](./src/bin/11.rs) | `131.1µs` | `5.2ms` |
25-
| [Day 12](./src/bin/12.rs) | `3.4ms` | `5.1ms` |
26-
| [Day 13](./src/bin/13.rs) | `44.0µs` | `39.5µs` |
27-
28-
**Total: 1062.58ms**
14+
| [Day 1](./src/bin/01.rs) | `65.5µs` | `85.5µs` |
15+
| [Day 2](./src/bin/02.rs) | `873.1µs` | `965.8µs` |
16+
| [Day 3](./src/bin/03.rs) | `269.4µs` | `286.9µs` |
17+
| [Day 4](./src/bin/04.rs) | `289.3µs` | `89.9µs` |
18+
| [Day 5](./src/bin/05.rs) | `184.0µs` | `275.0µs` |
19+
| [Day 6](./src/bin/06.rs) | `162.6µs` | `183.5ms` |
20+
| [Day 7](./src/bin/07.rs) | `1.1ms` | `335.8ms` |
21+
| [Day 8](./src/bin/08.rs) | `71.4µs` | `53.6µs` |
22+
| [Day 9](./src/bin/09.rs) | `118.0µs` | `541.1ms` |
23+
| [Day 10](./src/bin/10.rs) | `196.6µs` | `85.6µs` |
24+
| [Day 11](./src/bin/11.rs) | `132.3µs` | `5.3ms` |
25+
| [Day 12](./src/bin/12.rs) | `3.5ms` | `5.1ms` |
26+
| [Day 13](./src/bin/13.rs) | `45.1µs` | `39.6µs` |
27+
28+
**Total: 1079.69ms**
2929
<!--- benchmarking table --->
3030

3131

src/bin/06.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn part1(mtx: &Mtx) -> Option<usize> {
3636
while let Some('#') = get(mtx, r + dr, c + dc, r_max, c_max) {
3737
(dr, dc) = turn_right((dr, dc));
3838
}
39-
if let None = get(mtx, r + dr, c + dc, r_max, c_max) {
39+
if get(mtx, r + dr, c + dc, r_max, c_max).is_none() {
4040
break;
4141
}
4242
(r, c) = (r + dr, c + dc);
@@ -62,9 +62,12 @@ fn obstacle_loops(mtx: &mut Mtx, r: i32, c: i32, dr: i32, dc: i32, r_max: i32, c
6262
while let Some('#') = get(mtx, r + dr, c + dc, r_max, c_max) {
6363
(dr, dc) = turn_right((dr, dc));
6464
}
65-
if let None = get(mtx, r + dr, c + dc, r_max, c_max) {
65+
if get(mtx, r + dr, c + dc, r_max, c_max).is_none() {
6666
break;
6767
}
68+
// if let None = get(mtx, r + dr, c + dc, r_max, c_max) {
69+
// break;
70+
// }
6871
(r, c) = (r + dr, c + dc);
6972
}
7073
}
@@ -86,7 +89,7 @@ fn part2(mtx: &mut Mtx) -> Option<usize> {
8689
while let Some('#') = get(mtx, r + dr, c + dc, r_max, c_max) {
8790
(dr, dc) = turn_right((dr, dc));
8891
}
89-
if let None = get(mtx, r + dr, c + dc, r_max, c_max) {
92+
if get(mtx, r + dr, c + dc, r_max, c_max).is_none() {
9093
break;
9194
}
9295
(r, c) = (r + dr, c + dc);
@@ -110,18 +113,15 @@ pub fn part_one(input: &str) -> Option<usize> {
110113
.lines()
111114
.map(|line| line.chars().collect::<Vec<_>>())
112115
.collect::<Mtx>();
113-
let result = part1(&input);
114-
result
116+
part1(&input)
115117
}
116118

117119
pub fn part_two(input: &str) -> Option<usize> {
118120
let mut input = input
119121
.lines()
120122
.map(|line| line.chars().collect::<Vec<_>>())
121123
.collect::<Mtx>();
122-
let result = part2(&mut input);
123-
// println!("Part2: {:?}", result);
124-
result
124+
part2(&mut input)
125125
}
126126

127127
#[cfg(test)]

src/bin/10.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ advent_of_code::solution!(10);
22

33
use std::collections::HashMap;
44

5-
const DIRECTIONS: [(isize, isize); 4] = [(0, -1), (-1, 0), (1, 0), (0, 1)]; // Left, Up, Down, Right
6-
// Left, Up, Down, Right
7-
// let directions = [(0, -1), (-1, 0), (1, 0), (0, 1)];
5+
const DIRECTIONS: [(isize, isize); 4] = [(0, -1), (-1, 0), (1, 0), (0, 1)];
86

97
pub fn part_one_another(input: &str) -> Option<u32> {
108
let matrix: Vec<Vec<u32>> = input
@@ -39,8 +37,7 @@ pub fn part_one_another(input: &str) -> Option<u32> {
3937
let mut stack: Vec<(usize, usize)> = vec![];
4038
stack.push((x, y));
4139
let mut existing: HashMap<(usize, usize), bool> = HashMap::new();
42-
while stack.len() > 0 {
43-
let (cur_x, cur_y) = stack.pop().unwrap();
40+
while let Some((cur_x, cur_y)) = stack.pop() {
4441
let cur_val = matrix[cur_x][cur_y];
4542
if cur_val == 9 {
4643
existing.insert((cur_x, cur_y), true);
@@ -99,13 +96,11 @@ pub fn part_two(input: &str) -> Option<usize> {
9996
})
10097
.collect();
10198

102-
10399
for (x, y) in trailheads {
104100
let mut stack: Vec<(usize, usize)> = vec![];
105101
stack.push((x, y));
106102

107-
while stack.len() > 0 {
108-
let (current_x, current_y) = stack.pop().unwrap();
103+
while let Some((current_x, current_y)) = stack.pop() {
109104
let value = matrix[current_x][current_y];
110105
if value == 9 {
111106
result += 1;
@@ -116,10 +111,11 @@ pub fn part_two(input: &str) -> Option<usize> {
116111
let new_x: usize = (current_x as isize + dx) as usize;
117112
let new_y: usize = (current_y as isize + dy) as usize;
118113

119-
if new_x < matrix.len() && new_y < matrix[0].len() {
120-
if matrix[new_x][new_y] == value + 1 {
121-
stack.push((new_x, new_y));
122-
}
114+
if new_x < matrix.len()
115+
&& new_y < matrix[0].len()
116+
&& matrix[new_x][new_y] == value + 1
117+
{
118+
stack.push((new_x, new_y));
123119
}
124120
}
125121
}

src/bin/13.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub fn part_one(input: &str) -> Option<usize> {
2020
.split(|c: char| !c.is_ascii_digit())
2121
.filter(|w| !w.is_empty())
2222
.map(|w| w.parse().unwrap())
23-
.collect_tuple() {
23+
.collect_tuple()
24+
{
2425
Some(x) => x,
2526
None => continue,
2627
};
@@ -38,7 +39,8 @@ pub fn part_two(input: &str) -> Option<usize> {
3839
.split(|c: char| !c.is_ascii_digit())
3940
.filter(|w| !w.is_empty())
4041
.map(|w| w.parse().unwrap())
41-
.collect_tuple( ) {
42+
.collect_tuple()
43+
{
4244
Some(x) => x,
4345
None => continue,
4446
};

0 commit comments

Comments
 (0)