Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c22a128

Browse files
Year 2023 speed and code quality improvements
1 parent 2439fa7 commit c22a128

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
116116
| 7 | [Camel Cards](https://adventofcode.com/2023/day/7) | [Source](src/year2023/day07.rs) | 71 |
117117
| 8 | [Haunted Wasteland](https://adventofcode.com/2023/day/8) | [Source](src/year2023/day08.rs) | 34 |
118118
| 9 | [Mirage Maintenance](https://adventofcode.com/2023/day/9) | [Source](src/year2023/day09.rs) | 18 |
119-
| 10 | [Pipe Maze](https://adventofcode.com/2023/day/10) | [Source](src/year2023/day10.rs) | 41 |
119+
| 10 | [Pipe Maze](https://adventofcode.com/2023/day/10) | [Source](src/year2023/day10.rs) | 35 |
120120
| 11 | [Cosmic Expansion](https://adventofcode.com/2023/day/11) | [Source](src/year2023/day11.rs) | 12 |
121121
| 12 | [Hot Springs](https://adventofcode.com/2023/day/12) | [Source](src/year2023/day12.rs) | 387 |
122122
| 13 | [Point of Incidence](https://adventofcode.com/2023/day/13) | [Source](src/year2023/day13.rs) | 66 |

‎src/year2023/day10.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,34 @@ pub fn parse(input: &str) -> Input {
3838

3939
// Change direction at corner pieces.
4040
direction = match grid[position] {
41-
b'7' if direction == UP => LEFT,
42-
b'F' if direction == UP => RIGHT,
43-
b'J' if direction == DOWN => LEFT,
44-
b'L' if direction == DOWN => RIGHT,
45-
b'J' | b'L' => UP,
46-
b'7' | b'F' => DOWN,
41+
b'7' => {
42+
if direction == UP {
43+
LEFT
44+
} else {
45+
DOWN
46+
}
47+
}
48+
b'F' => {
49+
if direction == UP {
50+
RIGHT
51+
} else {
52+
DOWN
53+
}
54+
}
55+
b'J' => {
56+
if direction == DOWN {
57+
LEFT
58+
} else {
59+
UP
60+
}
61+
}
62+
b'L' => {
63+
if direction == DOWN {
64+
RIGHT
65+
} else {
66+
UP
67+
}
68+
}
4769
_ => {
4870
// We've looped all the way back to the start.
4971
area += determinant(corner, position);

‎src/year2023/day12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn part2(input: &[Spring<'_>]) -> u64 {
147147
let partial = solve(iter, 5);
148148
shared.fetch_add(partial, Ordering::Relaxed);
149149
});
150-
shared.load(Ordering::Relaxed)
150+
shared.into_inner()
151151
}
152152

153153
pub fn solve<'a, I>(iter: I, repeat: usize) -> u64

‎src/year2023/day16.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! according to the rules of each tile.
55
//!
66
//! To speed things up the next coordinate in each direction is precomputed for every point
7-
//! so that the empty spaces between mirrros and splitters are filled efficiently.
7+
//! so that the empty spaces between mirrors and splitters are filled efficiently.
88
//!
99
//! Some beams can enter a closed loop so we keep track of previously seen `(position, direction)`
1010
//! pairs and stop if we've seen a pair before.
@@ -129,7 +129,7 @@ pub fn part2(input: &Input) -> usize {
129129
// Use as many cores as possible to parallelize the search.
130130
spawn(|| worker(&shared));
131131

132-
shared.tiles.load(Ordering::Relaxed)
132+
shared.tiles.into_inner()
133133
}
134134

135135
/// Process starting locations from a shared queue.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /