Skip to content

Commit aced27a

Browse files
committed
Tidy code
1 parent d604727 commit aced27a

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

src/year2015/day02.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ pub fn parse(input: &str) -> Input {
1717
input
1818
.iter_unsigned()
1919
.chunk::<3>()
20-
.map(|chunk| {
21-
let mut gift = chunk;
22-
gift.sort_unstable();
23-
gift
20+
.map(|mut chunk| {
21+
chunk.sort_unstable();
22+
chunk
2423
})
2524
.collect()
2625
}

src/year2015/day19.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn part1(input: &Input<'_>) -> usize {
2828
// Group replacements of the same size together.
2929
for &(from, to) in replacements {
3030
let extra = to.len() - from.len();
31-
groups.entry(extra).or_insert(Vec::new()).push((from, to));
31+
groups.entry(extra).or_insert_with(Vec::new).push((from, to));
3232
}
3333

3434
for (_, group) in groups {

src/year2022/day03.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ fn mask(s: &str) -> u128 {
5555
/// Find the lowest set bit (there should only be one) then convert to priority using the
5656
/// given rules.
5757
fn priority(mask: u128) -> u32 {
58-
let zeroes = mask.trailing_zeros();
59-
match zeroes {
60-
65..=90 => zeroes - 38,
61-
97..=122 => zeroes - 96,
62-
_ => unreachable!(),
63-
}
58+
let bit = mask.trailing_zeros();
59+
if bit > 96 { bit - 96 } else { bit - 38 }
6460
}

src/year2023/day17.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn astar<const L: i32, const U: i32>(grid: &Grid<i32>) -> i32 {
5656
let heat = &grid.bytes;
5757

5858
let mut index = 0;
59-
let mut todo = repeat_with(|| Vec::with_capacity(1000)).take(100).collect::<Vec<_>>();
59+
let mut todo: Vec<_> = repeat_with(|| Vec::with_capacity(1000)).take(100).collect();
6060
let mut cost = vec![[i32::MAX; 2]; heat.len()];
6161

6262
// Start from the top left corner checking both vertical and horizontal directions.

src/year2023/day23.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ fn compress(input: &str) -> Graph {
327327
}
328328

329329
// Graph is undirected so add both edges.
330-
edges.entry(from).or_insert(Vec::new()).push(to);
331-
edges.entry(to).or_insert(Vec::new()).push(from);
330+
edges.entry(from).or_insert_with(Vec::new).push(to);
331+
edges.entry(to).or_insert_with(Vec::new).push(from);
332332
weight.insert((from, to), cost);
333333
weight.insert((to, from), cost);
334334

0 commit comments

Comments
 (0)