Skip to content

Commit e1c0470

Browse files
committed
clippy
1 parent af4a70a commit e1c0470

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

2024/day14/day14.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Puzzle {
6666
*quadrants.entry(q).or_default() += 1_u32;
6767
}
6868

69-
quadrants.values().fold(1, |acc, x| acc * x)
69+
quadrants.values().product::<u32>()
7070
}
7171

7272
/// Solve part two.

2024/day15/day15.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ fn save_warehouse(
110110
n: u32,
111111
moves: usize,
112112
) -> Result<(), Box<dyn std::error::Error>> {
113+
const SCALE: u32 = 11;
114+
113115
// limit the frame count
114116
if moves > 1000 && n % 20 != 0 {
115117
return Ok(());
@@ -118,8 +120,6 @@ fn save_warehouse(
118120
return Ok(());
119121
}
120122

121-
const SCALE: u32 = 11;
122-
123123
let width = u32::try_from(grid.width())? * SCALE;
124124
let height = u32::try_from(grid.height())? * SCALE;
125125

2024/day17/day17.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ impl Puzzle {
4242
let opcode = self.program[ip];
4343
let literal = self.program[ip + 1];
4444

45-
let combo = || {
46-
return match literal {
47-
0 | 1 | 2 | 3 => literal,
48-
4 => a,
49-
5 => b,
50-
6 => c,
51-
_ => panic!(),
52-
};
45+
let combo = || match literal {
46+
0..=3 => literal,
47+
4 => a,
48+
5 => b,
49+
6 => c,
50+
_ => panic!(),
5351
};
5452

5553
match opcode {
5654
0 => {
5755
// adv
58-
a = a >> literal;
56+
a >>= literal;
5957
}
6058
1 => {
6159
//bxl
@@ -120,7 +118,7 @@ impl Puzzle {
120118
1 => (format!("bxl {literal}"), format!("b ^= {literal}")),
121119
2 => (format!("bst {combo}"), format!("b = {combo} % 8")),
122120
3 => (format!("jnz {literal}"), format!("jump {literal} if a≠0")),
123-
4 => (format!("bxc"), format!("b ^= c")),
121+
4 => ("bxc".to_string(), "b ^= c".to_string()),
124122
5 => (format!("out {combo}"), format!("out {combo} % 8")),
125123
6 => (format!("bdv {combo}"), format!("b = a >> {combo}")),
126124
7 => (format!("cdv {combo}"), format!("c = a >> {combo}")),
@@ -137,7 +135,7 @@ impl Puzzle {
137135

138136
output
139137
.iter()
140-
.map(|x| x.to_string())
138+
.map(std::string::ToString::to_string)
141139
.collect::<Vec<String>>()
142140
.join(",")
143141
}
@@ -153,9 +151,9 @@ impl Puzzle {
153151
// jump 0 if a≠0
154152

155153
fn quine(&self, a: u64, i: usize, xor1: u64, xor2: u64) -> u64 {
156-
let target = self.program[i] as u64;
154+
let target = u64::from(self.program[i]);
157155

158-
let start_octal = if i == self.program.len() - 1 { 1 } else { 0 };
156+
let start_octal = u64::from(i == self.program.len() - 1);
159157

160158
for octal in start_octal..8 {
161159
let new_a = (a * 8) | octal;
@@ -189,10 +187,10 @@ impl Puzzle {
189187
return 0;
190188
}
191189

192-
let xor1 = xors[0] as u64;
193-
let xor2 = xors[1] as u64;
190+
let xor_1 = u64::from(xors[0]);
191+
let xor_2 = u64::from(xors[1]);
194192

195-
return self.quine(0, self.program.len() - 1, xor1, xor2);
193+
self.quine(0, self.program.len() - 1, xor_1, xor_2)
196194
}
197195
}
198196

2024/day19/day19.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ impl Puzzle {
1919

2020
let (patterns, designs) = data.split_once("\n\n").unwrap();
2121

22-
self.patterns = patterns.split(", ").map(|x| x.to_string()).collect();
23-
self.designs = designs.lines().map(|x| x.to_string()).collect();
22+
self.patterns = patterns
23+
.split(", ")
24+
.map(std::string::ToString::to_string)
25+
.collect();
26+
self.designs = designs
27+
.lines()
28+
.map(std::string::ToString::to_string)
29+
.collect();
2430
}
2531

2632
fn count_design_ways(&self, design: &str) -> u64 {

0 commit comments

Comments
 (0)