diff --git a/day01-gen-problem/src/main.rs b/day01-gen-problem/src/main.rs index adffead..a4e9761 100644 --- a/day01-gen-problem/src/main.rs +++ b/day01-gen-problem/src/main.rs @@ -8,8 +8,7 @@ const MAX_CALORY: usize = 30_000; fn main() { let outfile = ::std::env::args() - .skip(1) - .next() + .nth(1) .expect("Output file as first parameter"); let mut outfile = BufWriter::new(File::create(outfile).expect("Can write outfile")); let mut rng = rand::thread_rng(); diff --git a/day01/src/main.rs b/day01/src/main.rs index 980636d..ec64ede 100644 --- a/day01/src/main.rs +++ b/day01/src/main.rs @@ -60,8 +60,7 @@ impl TopThree { fn main() { let file = ::std::env::args() - .skip(1) - .next() + .nth(1) .unwrap_or_else(|| String::from("./input")); let file = BufReader::new(File::open(file).expect("Input file not found")); let TopCal { top, .. } = file diff --git a/day02-gen-problem/src/main.rs b/day02-gen-problem/src/main.rs index a12eb42..2996696 100644 --- a/day02-gen-problem/src/main.rs +++ b/day02-gen-problem/src/main.rs @@ -6,8 +6,7 @@ const LINE_COUNT: usize = 20_000_000; fn main() { let outfile = ::std::env::args() - .skip(1) - .next() + .nth(1) .expect("Output file as first parameter"); let mut outfile = BufWriter::new(File::create(outfile).expect("Can write outfile")); let mut rng = rand::thread_rng(); diff --git a/day02/src/main.rs b/day02/src/main.rs index 57aa074..9c317a8 100644 --- a/day02/src/main.rs +++ b/day02/src/main.rs @@ -25,9 +25,9 @@ fn calculate_game_score(line: String) -> usize { // Rock -> 1 // Paper -> 2 // Scissor -> 3 - (0, 0) => 3 + 0, - (1, 0) => 1 + 0, - (2, 0) => 2 + 0, + (0, 0) => 3, + (1, 0) => 1, + (2, 0) => 2, (0, 1) => 1 + 3, (1, 1) => 2 + 3, (2, 1) => 3 + 3, @@ -40,8 +40,7 @@ fn calculate_game_score(line: String) -> usize { fn main() { let file = ::std::env::args() - .skip(1) - .next() + .nth(1) .unwrap_or_else(|| String::from("./input")); let file = BufReader::new(File::open(file).expect("Input file not found")); let sum: usize = file diff --git a/day03-gen-problem/src/main.rs b/day03-gen-problem/src/main.rs index 4f96410..2bd397e 100644 --- a/day03-gen-problem/src/main.rs +++ b/day03-gen-problem/src/main.rs @@ -20,7 +20,7 @@ use std::{ }; lazy_static! { - static ref CHARS: Vec = ('a'..'z').chain('A'..'Z').collect(); + static ref CHARS: Vec = ('a'..='z').chain('A'..='Z').collect(); static ref ARGS: Args = Args::parse(); } @@ -44,7 +44,7 @@ impl Args { } fn replace_rand(rng: &mut rand::rngs::SmallRng, list: &mut Vec, item: I) { - debug_assert!(list.len() > 0); + debug_assert!(!list.is_empty()); let idx = rng.gen_range(0..list.len()); list[idx] = item; } @@ -114,7 +114,6 @@ fn main() { let mut rng = SmallRng::from_rng(rand::thread_rng()).expect("Init rng"); (0..ARGS.elf_groups) .flat_map(|_| gen_triple(&mut rng)) - .inspect(|line| debug_assert!(line.len() % 2 == 0)) .for_each(|line| writeln!(outfile, "{line}").expect("Writing works")); outfile.flush().expect("Flushing works"); } diff --git a/day03/src/main.rs b/day03/src/main.rs index 5c9fe74..1d8c7b5 100644 --- a/day03/src/main.rs +++ b/day03/src/main.rs @@ -32,7 +32,7 @@ impl IsTrue for Assert {} fn parse_chars>(line: S) -> Bitmask { line.as_ref() .as_bytes() - .into_iter() + .iter() .map(Bitmask::from_alpha) .reduce(std::ops::BitOr::bitor) .unwrap() diff --git a/day04/src/main.rs b/day04/src/main.rs index 6fe076c..d8216df 100644 --- a/day04/src/main.rs +++ b/day04/src/main.rs @@ -22,10 +22,10 @@ struct Counter { fn parse_line>(line: S) -> [RangeInclusive; 2] { let (first, second) = line .as_ref() - .split_once(",") + .split_once(',') .expect("A comma in every line"); - 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 (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"); [ first_from.parse().unwrap()..=first_to.parse().unwrap(), second_from.parse().unwrap()..=second_to.parse().unwrap(), diff --git a/day05/src/main.rs b/day05/src/main.rs index ab9dc9a..7f6a56a 100644 --- a/day05/src/main.rs +++ b/day05/src/main.rs @@ -84,7 +84,7 @@ impl Port { self.columns[mv.to].extend(moved); } /// 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 = self .columns .into_iter() @@ -105,7 +105,7 @@ where .map(|line| line.parse()) .map(Result::unwrap) .for_each(|mv| port.apply(mv, solve == SolvePuzzle::First)); - port.to_top_row_string() + port.into_top_row_string() } fn main() { diff --git a/day07/src/main.rs b/day07/src/main.rs index d1c95cb..e3c78a0 100644 --- a/day07/src/main.rs +++ b/day07/src/main.rs @@ -43,12 +43,9 @@ impl Collector { self.change_director_root() } else if line == "$ cd .." { self.change_directory_up() - } else if line.starts_with("$ cd ") { - let target = &line[5..]; + } else if let Some(target) = line.strip_prefix("$ cd ") { self.change_directory_to(target) - } else if line == "$ ls" { - // Just ignore - } else if line.starts_with("dir ") { + } else if line == "$ ls" || line.starts_with("dir ") { // Nothing to do } else { let (size, _label) = line.split_once(' ').expect("A dir list entry"); diff --git a/day08/src/main.rs b/day08/src/main.rs index fcc7d86..c63178b 100644 --- a/day08/src/main.rs +++ b/day08/src/main.rs @@ -166,7 +166,7 @@ fn print_scenic_view(reader: R) { .copied() .unwrap_or_default() + 1; - let sup = sup.checked_ilog2().unwrap_or_default(); + let _sup = sup.checked_ilog2().unwrap_or_default(); for row_idx in 0..height { let output: String = (0..width) .map(|col_idx| { @@ -177,7 +177,7 @@ fn print_scenic_view(reader: R) { 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( // score.checked_ilog2().unwrap_or_default() as usize, // sup as usize,