2024: clippies

This commit is contained in:
ktims committed 2026-12-02 14:09:23 -07:00
1 parent 966ac945ed
commit 2121d0dc55
7 files changed
+69 -41

No files matched your search

+37 -12
View File
@@ -55,8 +55,14 @@ impl NumberKeypadRobot {
// NOTE: no need to consider zig-zags since those paths will always require more button presses going back and forth
if (cur_pos.0 + x_ofs, cur_pos.1) != Self::pos_of(b'X') {
let mut x_first = Vec::new();
x_first.extend(repeat_n(if x_ofs > 0 { b'>' } else { b'<' }, x_ofs.abs() as usize));
x_first.extend(repeat_n(if y_ofs > 0 { b'v' } else { b'^' }, y_ofs.abs() as usize));
x_first.extend(repeat_n(
if x_ofs > 0 { b'>' } else { b'<' },
x_ofs.unsigned_abs() as usize,
));
x_first.extend(repeat_n(
if y_ofs > 0 { b'v' } else { b'^' },
y_ofs.unsigned_abs() as usize,
));
x_first.push(b'A');
paths.push({
let mut h = FxHashMap::default();
@@ -66,8 +72,14 @@ impl NumberKeypadRobot {
}
if (cur_pos.0, cur_pos.1 + y_ofs) != Self::pos_of(b'X') {
let mut y_first = Vec::new();
y_first.extend(repeat_n(if y_ofs > 0 { b'v' } else { b'^' }, y_ofs.abs() as usize));
y_first.extend(repeat_n(if x_ofs > 0 { b'>' } else { b'<' }, x_ofs.abs() as usize));
y_first.extend(repeat_n(
if y_ofs > 0 { b'v' } else { b'^' },
y_ofs.unsigned_abs() as usize,
));
y_first.extend(repeat_n(
if x_ofs > 0 { b'>' } else { b'<' },
x_ofs.unsigned_abs() as usize,
));
y_first.push(b'A');
paths.push({
let mut h = FxHashMap::default();
@@ -88,6 +100,7 @@ impl NumberKeypadRobot {
struct DirectionKeypadRobot {
pointing_at: u8,
child: Option<Box<KeypadRobot>>,
#[allow(unused)]
id: usize,
}
@@ -113,15 +126,27 @@ impl DirectionKeypadRobot {
if (cur_pos.0 + x_ofs, cur_pos.1) != Self::pos_of(b'X') {
let mut x_first = Vec::new();
x_first.extend(repeat_n(if x_ofs > 0 { b'>' } else { b'<' }, x_ofs.abs() as usize));
x_first.extend(repeat_n(if y_ofs > 0 { b'v' } else { b'^' }, y_ofs.abs() as usize));
x_first.extend(repeat_n(
if x_ofs > 0 { b'>' } else { b'<' },
x_ofs.unsigned_abs() as usize,
));
x_first.extend(repeat_n(
if y_ofs > 0 { b'v' } else { b'^' },
y_ofs.unsigned_abs() as usize,
));
x_first.push(b'A');
return x_first;
}
if (cur_pos.0, cur_pos.1 + y_ofs) != Self::pos_of(b'X') {
let mut y_first = Vec::new();
y_first.extend(repeat_n(if y_ofs > 0 { b'v' } else { b'^' }, y_ofs.abs() as usize));
y_first.extend(repeat_n(if x_ofs > 0 { b'>' } else { b'<' }, x_ofs.abs() as usize));
y_first.extend(repeat_n(
if y_ofs > 0 { b'v' } else { b'^' },
y_ofs.unsigned_abs() as usize,
));
y_first.extend(repeat_n(
if x_ofs > 0 { b'>' } else { b'<' },
x_ofs.unsigned_abs() as usize,
));
y_first.push(b'A');
return y_first;
}
@@ -155,7 +180,7 @@ impl DirectionKeypadRobot {
let path = self.path_to(&moves);
for path_move in path.split_inclusive(|m| *m == b'A') {
let entry = local_freqs.entry(path_move.to_vec()).or_insert(0);
*entry = *entry + count;
*entry += count;
}
}
my_frequencies.push(local_freqs);
@@ -200,20 +225,20 @@ fn run_robots(code: &Code, n: usize) -> i64 {
.unwrap();
sum += best;
}
return sum as i64 * code.num_val();
sum as i64 * code.num_val()
}
#[aoc(day21, part1)]
fn part1(input: &str) -> i64 {
let codes = parse(input);
codes.iter().map(|c| run_robots(c, 2)).sum::<i64>() as i64
codes.iter().map(|c| run_robots(c, 2)).sum::<i64>()
}
#[aoc(day21, part2)]
fn part2(input: &str) -> i64 {
let codes = parse(input);
for i in 0..26 {
let res = codes.iter().map(|c| run_robots(c, i)).sum::<i64>() as i64;
let res = codes.iter().map(|c| run_robots(c, i)).sum::<i64>();
println!("{i}: {res}");
}
0