From 242b284a59922c4d8889f8cf0f4eff1b5e68b133 Mon Sep 17 00:00:00 2001 From: Jur van den Berg Date: Sat, 10 Dec 2022 12:47:30 +0100 Subject: [PATCH] Blindly follow all clippy's decrees --- src/day01.rs | 2 +- src/day02.rs | 8 ++++---- src/day03.rs | 2 +- src/day04.rs | 11 ++++++----- src/day05.rs | 7 ++++--- src/day07.rs | 2 +- src/day08.rs | 2 +- src/day09.rs | 4 ++-- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/day01.rs b/src/day01.rs index 63a9ca9..07c0664 100644 --- a/src/day01.rs +++ b/src/day01.rs @@ -8,7 +8,7 @@ pub fn process_part_1(input: &str) -> u32 { }) .max() .unwrap(); - return result; + result } pub fn process_part_2(input: &str) -> u32 { diff --git a/src/day02.rs b/src/day02.rs index 0f6cf64..4532b92 100644 --- a/src/day02.rs +++ b/src/day02.rs @@ -37,7 +37,7 @@ pub fn process_part_1(input: &str) -> u32 { .lines() .map(|line| { let moves = line - .split(" ") + .split(' ') .map(|s| s.parse::().unwrap()) .collect::>(); match moves[1].partial_cmp(&moves[0]) { @@ -49,14 +49,14 @@ pub fn process_part_1(input: &str) -> u32 { }) .sum(); - return result; + result } pub fn process_part_2(input: &str) -> u32 { let result = input .lines() .map(|line| { - let moves = line.split(" ").collect::>(); + let moves = line.split(' ').collect::>(); let opponent_move: Move = moves[0].parse().unwrap(); match moves[1] { "X" => { @@ -85,7 +85,7 @@ pub fn process_part_2(input: &str) -> u32 { }) .sum(); - return result; + result } #[cfg(test)] diff --git a/src/day03.rs b/src/day03.rs index a46e5a7..657d837 100644 --- a/src/day03.rs +++ b/src/day03.rs @@ -35,7 +35,7 @@ pub fn process_part_2(input: &str) -> u32 { } }) .sum(); - return result; + result } #[cfg(test)] diff --git a/src/day04.rs b/src/day04.rs index 28ef92d..464cdc1 100644 --- a/src/day04.rs +++ b/src/day04.rs @@ -1,6 +1,9 @@ -use nom::IResult; use std::ops::RangeInclusive; +use nom::IResult; + +type RangePair = (RangeInclusive, RangeInclusive); + pub fn process_part_1(input: &str) -> usize { let (_, assignments) = section_assignments(input).unwrap(); assignments @@ -21,9 +24,7 @@ fn range_contains(haystack: &RangeInclusive, needle: &RangeInclusive) haystack.contains(needle.start()) && haystack.contains(needle.end()) } -fn section_assignments( - input: &str, -) -> IResult<&str, Vec<(RangeInclusive, RangeInclusive)>> { +fn section_assignments(input: &str) -> IResult<&str, Vec> { use nom::character::complete::newline; use nom::multi::separated_list1; @@ -31,7 +32,7 @@ fn section_assignments( Ok((input, ranges)) } -fn line(input: &str) -> IResult<&str, (RangeInclusive, RangeInclusive)> { +fn line(input: &str) -> IResult<&str, RangePair> { use nom::bytes::complete::tag; let (input, start) = sections(input)?; diff --git a/src/day05.rs b/src/day05.rs index 4c085fc..83a64cd 100644 --- a/src/day05.rs +++ b/src/day05.rs @@ -50,7 +50,8 @@ struct Move { to: u32, } -fn parse_crates(input: &str) -> IResult<&str, (Vec>, Vec, Vec)> { +type CrateStacks<'a> = Vec>; +fn parse_crates(input: &str) -> IResult<&str, (CrateStacks, Vec, Vec)> { let (input, crates_transposed) = parse_crate_stacks(input)?; let (input, _) = newline(input)?; let (input, crate_numbers) = separated_list1(tag(" "), parse_crate_name)(input)?; @@ -62,13 +63,13 @@ fn parse_crates(input: &str) -> IResult<&str, (Vec>, Vec, Vec [ [D, A], [E, B], [C] // (its transposed for pop() and push() magic :)) // it also unwraps all `None`'s from the lists - let crates: Vec> = (0..crates_transposed[0].len()) + let crates: CrateStacks = (0..crates_transposed[0].len()) .map(|i| { crates_transposed .iter() .map(|items| items[i]) .rev() - .filter_map(|item| item) + .flatten() .collect() }) .collect(); diff --git a/src/day07.rs b/src/day07.rs index c73daf6..6caa931 100644 --- a/src/day07.rs +++ b/src/day07.rs @@ -26,7 +26,7 @@ pub fn process_part_2(input: &str) -> u32 { directories .values() .filter(|&size| *size >= wanted_space) - .map(|&size| size) + .copied() .min() .unwrap_or(0) } diff --git a/src/day08.rs b/src/day08.rs index 502a7f0..c344297 100644 --- a/src/day08.rs +++ b/src/day08.rs @@ -52,7 +52,7 @@ pub fn process_part_2(input: &str) -> usize { fn parse_trees(input: &str) -> Vec> { input .trim() - .split("\n") + .split('\n') .map(|i| i.chars().map(|c| c.to_digit(10).unwrap() as u8).collect()) .collect() } diff --git a/src/day09.rs b/src/day09.rs index cd72e41..f99536b 100644 --- a/src/day09.rs +++ b/src/day09.rs @@ -11,13 +11,13 @@ use nom::IResult; pub fn process_part_1(input: &str) -> usize { let (_, moves) = parse(input).unwrap(); let visited = simulate_rope(moves, 2); - return visited.len(); + visited.len() } pub fn process_part_2(input: &str) -> usize { let (_, moves) = parse(input).unwrap(); let visited = simulate_rope(moves, 10); - return visited.len(); + visited.len() } fn simulate_rope(moves: Vec<(Direction, usize)>, rope_size: usize) -> BTreeSet<(i32, i32)> {