2025: clippies
This commit is contained in:
3 files changed
+20
-17
No files matched your search
+5
-6
@@ -1,6 +1,5 @@
|
||||
use std::{
|
||||
collections::{BinaryHeap, VecDeque},
|
||||
hash::Hash,
|
||||
iter::{repeat, repeat_n},
|
||||
};
|
||||
|
||||
@@ -73,8 +72,8 @@ impl From<&str> for MachineDefinition {
|
||||
|
||||
MachineDefinition {
|
||||
desired: parts["desired"].chars().map(|c| c == '#').collect(),
|
||||
buttons: buttons,
|
||||
buttons2: buttons2,
|
||||
buttons,
|
||||
buttons2,
|
||||
buttons_max: i16x16::new(buttons_max),
|
||||
joltages: i16x16::new(joltages),
|
||||
}
|
||||
@@ -127,7 +126,7 @@ impl<'a> JoltMachine<'a> {
|
||||
// // new_joltage[*jolt] += 1;
|
||||
// // }
|
||||
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;
|
||||
if new_joltage == self.d.joltages {
|
||||
(new_presses, None)
|
||||
@@ -147,7 +146,7 @@ impl<'a> JoltMachine<'a> {
|
||||
.buttons
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, _but)| self.press_jolts(i, &presses))
|
||||
.map(|(i, _but)| self.press_jolts(i, presses))
|
||||
// .inspect(|(p, o)| println!(" {p:?} {o:?}\n"))
|
||||
// joltages monotonically increase, so cull any where a joltage is higher than needed
|
||||
.filter(|(presses, candidate)| {
|
||||
@@ -246,7 +245,7 @@ fn find_best_jolts(md: &MachineDefinition) -> usize {
|
||||
machine: m,
|
||||
});
|
||||
|
||||
let mut pb = ProgressBar::no_length()
|
||||
let pb = ProgressBar::no_length()
|
||||
.with_style(
|
||||
ProgressStyle::with_template(
|
||||
"[{elapsed_precise}/{eta_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {per_sec}",
|
||||
|
||||
+3
-6
@@ -1,8 +1,6 @@
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use grid::{Coord2d, Grid, MirrorAxis};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use itertools::Itertools;
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
use std::iter::repeat_n;
|
||||
@@ -139,10 +137,9 @@ impl PresentsProblem {
|
||||
y: y as i64,
|
||||
},
|
||||
i,
|
||||
) {
|
||||
if self.place_next(new_t, cur + 1, cache) {
|
||||
return true;
|
||||
}
|
||||
) && self.place_next(new_t, cur + 1, cache)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -22,7 +22,7 @@ fn parse(input: &str) -> Vec<Coord2d> {
|
||||
}
|
||||
|
||||
#[aoc(day9, part1)]
|
||||
fn part1(input: &Vec<Coord2d>) -> u64 {
|
||||
fn part1(input: &[Coord2d]) -> u64 {
|
||||
input
|
||||
.iter()
|
||||
.tuple_combinations()
|
||||
@@ -62,6 +62,7 @@ fn build_grid(reds: &Vec<Coord2d>) -> Grid<u8> {
|
||||
grid
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn build_hashgrid(reds: &Vec<Coord2d>) -> HashMap<Coord2d, u8> {
|
||||
let mut grid = HashMap::new();
|
||||
let mut prev = reds.last().unwrap();
|
||||
@@ -88,6 +89,7 @@ fn build_hashgrid(reds: &Vec<Coord2d>) -> HashMap<Coord2d, u8> {
|
||||
grid
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn flood_fill(grid: &mut Grid<u8>, pos: Coord2d) {
|
||||
if grid.get(&pos) != Some(&b'.') {
|
||||
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>) {
|
||||
let mut span_added = false;
|
||||
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)]
|
||||
fn part2(reds: &Vec<Coord2d>) -> u64 {
|
||||
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)
|
||||
}
|
||||
|
||||
fn line_square_intersection<LT: AsCoord2d, ST: AsCoord2d>(&(l1, l2): &(<, <), &(sq1, sq2): &(&ST, &ST)) -> bool
|
||||
#[allow(unused)]
|
||||
fn line_square_intersection<LT, ST>(&(l1, l2): &(<, <), &(sq1, sq2): &(&ST, &ST)) -> bool
|
||||
where
|
||||
LT: Clone + Display,
|
||||
ST: Clone + Display,
|
||||
LT: Clone + Display + AsCoord2d,
|
||||
ST: Clone + Display + AsCoord2d,
|
||||
{
|
||||
let min_x = min(sq1.x(), sq2.x());
|
||||
let max_x = max(sq1.x(), sq2.x());
|
||||
@@ -216,6 +221,7 @@ where
|
||||
trait Rectangle {
|
||||
fn top_left(&self) -> Coord2d;
|
||||
fn bottom_right(&self) -> Coord2d;
|
||||
#[allow(unused)]
|
||||
fn in_bounds<T: AsCoord2d>(&self, b: &T) -> bool {
|
||||
b.x() >= self.top_left().x
|
||||
&& b.x() <= self.bottom_right().x()
|
||||
@@ -245,6 +251,7 @@ impl Rectangle for (&Coord2d, &Coord2d) {
|
||||
}
|
||||
|
||||
// true = clockwise
|
||||
#[allow(unused)]
|
||||
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 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)]
|
||||
fn part2_lines(reds: &Vec<Coord2d>) -> u64 {
|
||||
fn part2_lines(reds: &[Coord2d]) -> u64 {
|
||||
// let mut grid = build_hashgrid(reds);
|
||||
// let mut grid = build_grid(reds);
|
||||
// // println!("{grid}");
|
||||
|
||||
Reference in new issue
Block a user