Apply clippy fixes

This commit is contained in:
Malte Tammena 2022-12-09 21:46:33 +01:00
parent 57abfe3195
commit 3eaea9577a
10 changed files with 19 additions and 27 deletions

View file

@ -8,8 +8,7 @@ const MAX_CALORY: usize = 30_000;
fn main() { fn main() {
let outfile = ::std::env::args() let outfile = ::std::env::args()
.skip(1) .nth(1)
.next()
.expect("Output file as first parameter"); .expect("Output file as first parameter");
let mut outfile = BufWriter::new(File::create(outfile).expect("Can write outfile")); let mut outfile = BufWriter::new(File::create(outfile).expect("Can write outfile"));
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();

View file

@ -60,8 +60,7 @@ impl TopThree {
fn main() { fn main() {
let file = ::std::env::args() let file = ::std::env::args()
.skip(1) .nth(1)
.next()
.unwrap_or_else(|| String::from("./input")); .unwrap_or_else(|| String::from("./input"));
let file = BufReader::new(File::open(file).expect("Input file not found")); let file = BufReader::new(File::open(file).expect("Input file not found"));
let TopCal { top, .. } = file let TopCal { top, .. } = file

View file

@ -6,8 +6,7 @@ const LINE_COUNT: usize = 20_000_000;
fn main() { fn main() {
let outfile = ::std::env::args() let outfile = ::std::env::args()
.skip(1) .nth(1)
.next()
.expect("Output file as first parameter"); .expect("Output file as first parameter");
let mut outfile = BufWriter::new(File::create(outfile).expect("Can write outfile")); let mut outfile = BufWriter::new(File::create(outfile).expect("Can write outfile"));
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();

View file

@ -25,9 +25,9 @@ fn calculate_game_score(line: String) -> usize {
// Rock -> 1 // Rock -> 1
// Paper -> 2 // Paper -> 2
// Scissor -> 3 // Scissor -> 3
(0, 0) => 3 + 0, (0, 0) => 3,
(1, 0) => 1 + 0, (1, 0) => 1,
(2, 0) => 2 + 0, (2, 0) => 2,
(0, 1) => 1 + 3, (0, 1) => 1 + 3,
(1, 1) => 2 + 3, (1, 1) => 2 + 3,
(2, 1) => 3 + 3, (2, 1) => 3 + 3,
@ -40,8 +40,7 @@ fn calculate_game_score(line: String) -> usize {
fn main() { fn main() {
let file = ::std::env::args() let file = ::std::env::args()
.skip(1) .nth(1)
.next()
.unwrap_or_else(|| String::from("./input")); .unwrap_or_else(|| String::from("./input"));
let file = BufReader::new(File::open(file).expect("Input file not found")); let file = BufReader::new(File::open(file).expect("Input file not found"));
let sum: usize = file let sum: usize = file

View file

@ -20,7 +20,7 @@ use std::{
}; };
lazy_static! { lazy_static! {
static ref CHARS: Vec<char> = ('a'..'z').chain('A'..'Z').collect(); static ref CHARS: Vec<char> = ('a'..='z').chain('A'..='Z').collect();
static ref ARGS: Args = Args::parse(); static ref ARGS: Args = Args::parse();
} }
@ -44,7 +44,7 @@ impl Args {
} }
fn replace_rand<I>(rng: &mut rand::rngs::SmallRng, list: &mut Vec<I>, item: I) { fn replace_rand<I>(rng: &mut rand::rngs::SmallRng, list: &mut Vec<I>, item: I) {
debug_assert!(list.len() > 0); debug_assert!(!list.is_empty());
let idx = rng.gen_range(0..list.len()); let idx = rng.gen_range(0..list.len());
list[idx] = item; list[idx] = item;
} }
@ -114,7 +114,6 @@ fn main() {
let mut rng = SmallRng::from_rng(rand::thread_rng()).expect("Init rng"); let mut rng = SmallRng::from_rng(rand::thread_rng()).expect("Init rng");
(0..ARGS.elf_groups) (0..ARGS.elf_groups)
.flat_map(|_| gen_triple(&mut rng)) .flat_map(|_| gen_triple(&mut rng))
.inspect(|line| debug_assert!(line.len() % 2 == 0))
.for_each(|line| writeln!(outfile, "{line}").expect("Writing works")); .for_each(|line| writeln!(outfile, "{line}").expect("Writing works"));
outfile.flush().expect("Flushing works"); outfile.flush().expect("Flushing works");
} }

View file

@ -32,7 +32,7 @@ impl IsTrue for Assert<true> {}
fn parse_chars<S: AsRef<str>>(line: S) -> Bitmask { fn parse_chars<S: AsRef<str>>(line: S) -> Bitmask {
line.as_ref() line.as_ref()
.as_bytes() .as_bytes()
.into_iter() .iter()
.map(Bitmask::from_alpha) .map(Bitmask::from_alpha)
.reduce(std::ops::BitOr::bitor) .reduce(std::ops::BitOr::bitor)
.unwrap() .unwrap()

View file

@ -22,10 +22,10 @@ struct Counter {
fn parse_line<S: AsRef<str>>(line: S) -> [RangeInclusive<usize>; 2] { fn parse_line<S: AsRef<str>>(line: S) -> [RangeInclusive<usize>; 2] {
let (first, second) = line let (first, second) = line
.as_ref() .as_ref()
.split_once(",") .split_once(',')
.expect("A comma in every line"); .expect("A comma in every line");
let (first_from, first_to) = first.split_once("-").expect("A range with a dash"); let (first_from, first_to) = first.split_once('-').expect("A range with a dash");
let (second_from, second_to) = second.split_once("-").expect("A range with a dash"); let (second_from, second_to) = second.split_once('-').expect("A range with a dash");
[ [
first_from.parse().unwrap()..=first_to.parse().unwrap(), first_from.parse().unwrap()..=first_to.parse().unwrap(),
second_from.parse().unwrap()..=second_to.parse().unwrap(), second_from.parse().unwrap()..=second_to.parse().unwrap(),

View file

@ -84,7 +84,7 @@ impl Port {
self.columns[mv.to].extend(moved); self.columns[mv.to].extend(moved);
} }
/// Read the letters on the top row of the container stacks. /// Read the letters on the top row of the container stacks.
fn to_top_row_string(self) -> String { fn into_top_row_string(self) -> String {
let bytes: Vec<u8> = self let bytes: Vec<u8> = self
.columns .columns
.into_iter() .into_iter()
@ -105,7 +105,7 @@ where
.map(|line| line.parse()) .map(|line| line.parse())
.map(Result::unwrap) .map(Result::unwrap)
.for_each(|mv| port.apply(mv, solve == SolvePuzzle::First)); .for_each(|mv| port.apply(mv, solve == SolvePuzzle::First));
port.to_top_row_string() port.into_top_row_string()
} }
fn main() { fn main() {

View file

@ -43,12 +43,9 @@ impl<Ext: CollectorExt> Collector<Ext> {
self.change_director_root() self.change_director_root()
} else if line == "$ cd .." { } else if line == "$ cd .." {
self.change_directory_up() self.change_directory_up()
} else if line.starts_with("$ cd ") { } else if let Some(target) = line.strip_prefix("$ cd ") {
let target = &line[5..];
self.change_directory_to(target) self.change_directory_to(target)
} else if line == "$ ls" { } else if line == "$ ls" || line.starts_with("dir ") {
// Just ignore
} else if line.starts_with("dir ") {
// Nothing to do // Nothing to do
} else { } else {
let (size, _label) = line.split_once(' ').expect("A dir list entry"); let (size, _label) = line.split_once(' ').expect("A dir list entry");

View file

@ -166,7 +166,7 @@ fn print_scenic_view<R: BufRead>(reader: R) {
.copied() .copied()
.unwrap_or_default() .unwrap_or_default()
+ 1; + 1;
let sup = sup.checked_ilog2().unwrap_or_default(); let _sup = sup.checked_ilog2().unwrap_or_default();
for row_idx in 0..height { for row_idx in 0..height {
let output: String = (0..width) let output: String = (0..width)
.map(|col_idx| { .map(|col_idx| {
@ -177,7 +177,7 @@ fn print_scenic_view<R: BufRead>(reader: R) {
visible_trees[row_idx][col_idx], visible_trees[row_idx][col_idx],
) )
}) })
.map(|(col_idx, tree, score, is_visible)| { .map(|(col_idx, tree, _score, is_visible)| {
// let col = ::colorous::WARM.eval_rational( // let col = ::colorous::WARM.eval_rational(
// score.checked_ilog2().unwrap_or_default() as usize, // score.checked_ilog2().unwrap_or_default() as usize,
// sup as usize, // sup as usize,