Skip to content

Commit c682cb0

Browse files
committed
Clippy
1 parent 44bf67f commit c682cb0

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/y2019/day24.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl BitGrid {
9191
// (4,4) = 1 << 24 = 16777216
9292
fn mask(x: i32, y: i32) -> u32 {
9393
if (0..5).contains(&x) && (0..5).contains(&y) {
94-
1 << y * 5 + x
94+
1 << (y * 5 + x)
9595
} else {
9696
0
9797
}
@@ -137,9 +137,7 @@ struct InfiniteGrid {
137137

138138
impl InfiniteGrid {
139139
fn get(&self, depth: i32, x: i32, y: i32) -> bool {
140-
if depth < 0 || depth as usize >= self.grids.len() {
141-
false
142-
} else if x == 2 && y == 2 {
140+
if depth < 0 || depth as usize >= self.grids.len() || (x == 2 && y == 2) {
143141
false
144142
} else {
145143
self.grids[depth as usize].get(x, y)
@@ -222,14 +220,14 @@ impl InfiniteGrid {
222220
let mut data = 0;
223221
for y in 0..5 {
224222
for x in 0..5 {
225-
if !(x == 2 && y == 2) {
226-
if match (self.get(depth, x, y), self.count_neighbours(depth, x, y)) {
223+
if !(x == 2 && y == 2)
224+
&& match (self.get(depth, x, y), self.count_neighbours(depth, x, y)) {
227225
(true, 1) => true,
228226
(false, 1 | 2) => true,
229227
(_, _) => false,
230-
} {
231-
data += BitGrid::mask(x, y);
232228
}
229+
{
230+
data += BitGrid::mask(x, y);
233231
}
234232
}
235233
}
@@ -238,10 +236,10 @@ impl InfiniteGrid {
238236
}
239237

240238
// remove empty grids at ends
241-
while grids.len() > 0 && grids[0].biodiversity_rating() == 0 {
239+
while !grids.is_empty() && grids[0].biodiversity_rating() == 0 {
242240
grids.pop_front();
243241
}
244-
while grids.len() > 0 && grids[grids.len() - 1].biodiversity_rating() == 0 {
242+
while !grids.is_empty() && grids[grids.len() - 1].biodiversity_rating() == 0 {
245243
grids.pop_back();
246244
}
247245

src/y2019/day25.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ fn find_code(vm: &mut Vm) -> String {
144144
input += "south\n";
145145

146146
let output = execute(vm, &input);
147-
if output.contains("Droids on this ship are heavier") {
148-
} else if output.contains("Droids on this ship are lighter") {
147+
if output.contains("Droids on this ship are heavier")
148+
|| output.contains("Droids on this ship are lighter")
149+
{
149150
} else if output.contains("You may proceed.") {
150151
//println!(
151152
// "items needed: {:?}",
@@ -156,6 +157,8 @@ fn find_code(vm: &mut Vm) -> String {
156157
words_iter.position(|s| s == "typing");
157158
let code = words_iter.next();
158159
return code.unwrap().to_string();
160+
} else {
161+
panic!("Unexpected output: {:?}", output);
159162
}
160163
}
161164
}

0 commit comments

Comments
 (0)