2025: clippies

This commit is contained in:
ktims committed 2026-12-02 14:14:09 -07:00
1 parent 2121d0dc55
commit 0111a3903e
3 files changed
+19 -16

No files matched your search

+5 -6
View File
@@ -1,6 +1,5 @@
use std::{ use std::{
collections::{BinaryHeap, VecDeque}, collections::{BinaryHeap, VecDeque},
hash::Hash,
iter::{repeat, repeat_n}, iter::{repeat, repeat_n},
}; };
@@ -73,8 +72,8 @@ impl From<&str> for MachineDefinition {
MachineDefinition { MachineDefinition {
desired: parts["desired"].chars().map(|c| c == '#').collect(), desired: parts["desired"].chars().map(|c| c == '#').collect(),
buttons: buttons, buttons,
buttons2: buttons2, buttons2,
buttons_max: i16x16::new(buttons_max), buttons_max: i16x16::new(buttons_max),
joltages: i16x16::new(joltages), joltages: i16x16::new(joltages),
} }
@@ -127,7 +126,7 @@ impl<'a> JoltMachine<'a> {
// // new_joltage[*jolt] += 1; // // new_joltage[*jolt] += 1;
// // } // // }
let new_joltage = self.joltages + self.d.buttons2[button]; let new_joltage = self.joltages + self.d.buttons2[button];
let mut new_presses = presses.clone(); let mut new_presses = *presses;
new_presses.as_mut_array()[button] += 1; new_presses.as_mut_array()[button] += 1;
if new_joltage == self.d.joltages { if new_joltage == self.d.joltages {
(new_presses, None) (new_presses, None)
@@ -147,7 +146,7 @@ impl<'a> JoltMachine<'a> {
.buttons .buttons
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, _but)| self.press_jolts(i, &presses)) .map(|(i, _but)| self.press_jolts(i, presses))
// .inspect(|(p, o)| println!(" {p:?} {o:?}\n")) // .inspect(|(p, o)| println!(" {p:?} {o:?}\n"))
// joltages monotonically increase, so cull any where a joltage is higher than needed // joltages monotonically increase, so cull any where a joltage is higher than needed
.filter(|(presses, candidate)| { .filter(|(presses, candidate)| {
@@ -246,7 +245,7 @@ fn find_best_jolts(md: &MachineDefinition) -> usize {
machine: m, machine: m,
}); });
let mut pb = ProgressBar::no_length() let pb = ProgressBar::no_length()
.with_style( .with_style(
ProgressStyle::with_template( ProgressStyle::with_template(
"[{elapsed_precise}/{eta_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {per_sec}", "[{elapsed_precise}/{eta_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {per_sec}",
+2 -5
View File
@@ -1,8 +1,6 @@
use aoc_runner_derive::{aoc, aoc_generator}; use aoc_runner_derive::{aoc, aoc_generator};
use grid::{Coord2d, Grid, MirrorAxis}; use grid::{Coord2d, Grid, MirrorAxis};
use indicatif::{ProgressBar, ProgressStyle};
use itertools::Itertools; use itertools::Itertools;
use rayon::iter::IntoParallelRefIterator;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt::Display; use std::fmt::Display;
use std::iter::repeat_n; use std::iter::repeat_n;
@@ -139,14 +137,13 @@ impl PresentsProblem {
y: y as i64, y: y as i64,
}, },
i, i,
) { ) && self.place_next(new_t, cur + 1, cache)
if self.place_next(new_t, cur + 1, cache) { {
return true; return true;
} }
} }
} }
} }
}
cache.insert((cur, t.area.clone())); cache.insert((cur, t.area.clone()));
false false
} }
+12 -5
View File
@@ -22,7 +22,7 @@ fn parse(input: &str) -> Vec<Coord2d> {
} }
#[aoc(day9, part1)] #[aoc(day9, part1)]
fn part1(input: &Vec<Coord2d>) -> u64 { fn part1(input: &[Coord2d]) -> u64 {
input input
.iter() .iter()
.tuple_combinations() .tuple_combinations()
@@ -62,6 +62,7 @@ fn build_grid(reds: &Vec<Coord2d>) -> Grid<u8> {
grid grid
} }
#[allow(unused)]
fn build_hashgrid(reds: &Vec<Coord2d>) -> HashMap<Coord2d, u8> { fn build_hashgrid(reds: &Vec<Coord2d>) -> HashMap<Coord2d, u8> {
let mut grid = HashMap::new(); let mut grid = HashMap::new();
let mut prev = reds.last().unwrap(); let mut prev = reds.last().unwrap();
@@ -88,6 +89,7 @@ fn build_hashgrid(reds: &Vec<Coord2d>) -> HashMap<Coord2d, u8> {
grid grid
} }
#[allow(unused)]
fn flood_fill(grid: &mut Grid<u8>, pos: Coord2d) { fn flood_fill(grid: &mut Grid<u8>, pos: Coord2d) {
if grid.get(&pos) != Some(&b'.') { if grid.get(&pos) != Some(&b'.') {
return; return;
@@ -109,6 +111,7 @@ fn flood_fill(grid: &mut Grid<u8>, pos: Coord2d) {
} }
} }
#[allow(unused)]
fn flood_scan(grid: &mut Grid<u8>, lx: i64, rx: i64, y: i64, q: &mut VecDeque<Coord2d>) { fn flood_scan(grid: &mut Grid<u8>, lx: i64, rx: i64, y: i64, q: &mut VecDeque<Coord2d>) {
let mut span_added = false; let mut span_added = false;
for x in lx..rx { for x in lx..rx {
@@ -121,6 +124,7 @@ fn flood_scan(grid: &mut Grid<u8>, lx: i64, rx: i64, y: i64, q: &mut VecDeque<Co
} }
} }
#[allow(unused)]
// #[aoc(day9, part2, Brute)] // #[aoc(day9, part2, Brute)]
fn part2(reds: &Vec<Coord2d>) -> u64 { fn part2(reds: &Vec<Coord2d>) -> u64 {
let mut grid = build_grid(reds); let mut grid = build_grid(reds);
@@ -162,10 +166,11 @@ fn part2(reds: &Vec<Coord2d>) -> u64 {
(a.x().abs_diff(b.x()) + 1) * (a.y().abs_diff(b.y()) + 1) (a.x().abs_diff(b.x()) + 1) * (a.y().abs_diff(b.y()) + 1)
} }
fn line_square_intersection<LT: AsCoord2d, ST: AsCoord2d>(&(l1, l2): &(&LT, &LT), &(sq1, sq2): &(&ST, &ST)) -> bool #[allow(unused)]
fn line_square_intersection<LT, ST>(&(l1, l2): &(&LT, &LT), &(sq1, sq2): &(&ST, &ST)) -> bool
where where
LT: Clone + Display, LT: Clone + Display + AsCoord2d,
ST: Clone + Display, ST: Clone + Display + AsCoord2d,
{ {
let min_x = min(sq1.x(), sq2.x()); let min_x = min(sq1.x(), sq2.x());
let max_x = max(sq1.x(), sq2.x()); let max_x = max(sq1.x(), sq2.x());
@@ -216,6 +221,7 @@ where
trait Rectangle { trait Rectangle {
fn top_left(&self) -> Coord2d; fn top_left(&self) -> Coord2d;
fn bottom_right(&self) -> Coord2d; fn bottom_right(&self) -> Coord2d;
#[allow(unused)]
fn in_bounds<T: AsCoord2d>(&self, b: &T) -> bool { fn in_bounds<T: AsCoord2d>(&self, b: &T) -> bool {
b.x() >= self.top_left().x b.x() >= self.top_left().x
&& b.x() <= self.bottom_right().x() && b.x() <= self.bottom_right().x()
@@ -245,6 +251,7 @@ impl Rectangle for (&Coord2d, &Coord2d) {
} }
// true = clockwise // true = clockwise
#[allow(unused)]
fn outside_points(prev: &Coord2d, cur: &Coord2d, next: &Coord2d) -> Vec<Coord2d> { fn outside_points(prev: &Coord2d, cur: &Coord2d, next: &Coord2d) -> Vec<Coord2d> {
let l1_diff = ((cur.x - prev.x).signum(), (cur.y - prev.y).signum()); let l1_diff = ((cur.x - prev.x).signum(), (cur.y - prev.y).signum());
let l2_diff = ((next.x - cur.x).signum(), (next.y - cur.y).signum()); let l2_diff = ((next.x - cur.x).signum(), (next.y - cur.y).signum());
@@ -269,7 +276,7 @@ fn outside_points(prev: &Coord2d, cur: &Coord2d, next: &Coord2d) -> Vec<Coord2d>
} }
#[aoc(day9, part2, Lines)] #[aoc(day9, part2, Lines)]
fn part2_lines(reds: &Vec<Coord2d>) -> u64 { fn part2_lines(reds: &[Coord2d]) -> u64 {
// let mut grid = build_hashgrid(reds); // let mut grid = build_hashgrid(reds);
// let mut grid = build_grid(reds); // let mut grid = build_grid(reds);
// // println!("{grid}"); // // println!("{grid}");