Blindly follow all clippy's decrees

This commit is contained in:
2022-12-10 12:47:30 +01:00
parent fd764a46f1
commit 242b284a59
8 changed files with 20 additions and 18 deletions

View File

@@ -8,7 +8,7 @@ pub fn process_part_1(input: &str) -> u32 {
}) })
.max() .max()
.unwrap(); .unwrap();
return result; result
} }
pub fn process_part_2(input: &str) -> u32 { pub fn process_part_2(input: &str) -> u32 {

View File

@@ -37,7 +37,7 @@ pub fn process_part_1(input: &str) -> u32 {
.lines() .lines()
.map(|line| { .map(|line| {
let moves = line let moves = line
.split(" ") .split(' ')
.map(|s| s.parse::<Move>().unwrap()) .map(|s| s.parse::<Move>().unwrap())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
match moves[1].partial_cmp(&moves[0]) { match moves[1].partial_cmp(&moves[0]) {
@@ -49,14 +49,14 @@ pub fn process_part_1(input: &str) -> u32 {
}) })
.sum(); .sum();
return result; result
} }
pub fn process_part_2(input: &str) -> u32 { pub fn process_part_2(input: &str) -> u32 {
let result = input let result = input
.lines() .lines()
.map(|line| { .map(|line| {
let moves = line.split(" ").collect::<Vec<_>>(); let moves = line.split(' ').collect::<Vec<_>>();
let opponent_move: Move = moves[0].parse().unwrap(); let opponent_move: Move = moves[0].parse().unwrap();
match moves[1] { match moves[1] {
"X" => { "X" => {
@@ -85,7 +85,7 @@ pub fn process_part_2(input: &str) -> u32 {
}) })
.sum(); .sum();
return result; result
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -35,7 +35,7 @@ pub fn process_part_2(input: &str) -> u32 {
} }
}) })
.sum(); .sum();
return result; result
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -1,6 +1,9 @@
use nom::IResult;
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
use nom::IResult;
type RangePair = (RangeInclusive<u32>, RangeInclusive<u32>);
pub fn process_part_1(input: &str) -> usize { pub fn process_part_1(input: &str) -> usize {
let (_, assignments) = section_assignments(input).unwrap(); let (_, assignments) = section_assignments(input).unwrap();
assignments assignments
@@ -21,9 +24,7 @@ fn range_contains(haystack: &RangeInclusive<u32>, needle: &RangeInclusive<u32>)
haystack.contains(needle.start()) && haystack.contains(needle.end()) haystack.contains(needle.start()) && haystack.contains(needle.end())
} }
fn section_assignments( fn section_assignments(input: &str) -> IResult<&str, Vec<RangePair>> {
input: &str,
) -> IResult<&str, Vec<(RangeInclusive<u32>, RangeInclusive<u32>)>> {
use nom::character::complete::newline; use nom::character::complete::newline;
use nom::multi::separated_list1; use nom::multi::separated_list1;
@@ -31,7 +32,7 @@ fn section_assignments(
Ok((input, ranges)) Ok((input, ranges))
} }
fn line(input: &str) -> IResult<&str, (RangeInclusive<u32>, RangeInclusive<u32>)> { fn line(input: &str) -> IResult<&str, RangePair> {
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
let (input, start) = sections(input)?; let (input, start) = sections(input)?;

View File

@@ -50,7 +50,8 @@ struct Move {
to: u32, to: u32,
} }
fn parse_crates(input: &str) -> IResult<&str, (Vec<Vec<&str>>, Vec<u32>, Vec<Move>)> { type CrateStacks<'a> = Vec<Vec<&'a str>>;
fn parse_crates(input: &str) -> IResult<&str, (CrateStacks, Vec<u32>, Vec<Move>)> {
let (input, crates_transposed) = parse_crate_stacks(input)?; let (input, crates_transposed) = parse_crate_stacks(input)?;
let (input, _) = newline(input)?; let (input, _) = newline(input)?;
let (input, crate_numbers) = separated_list1(tag(" "), parse_crate_name)(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<&str>>, Vec<u32>, Vec<Mov
// ] => [ [D, A], [E, B], [C] // ] => [ [D, A], [E, B], [C]
// (its transposed for pop() and push() magic :)) // (its transposed for pop() and push() magic :))
// it also unwraps all `None`'s from the lists // it also unwraps all `None`'s from the lists
let crates: Vec<Vec<&str>> = (0..crates_transposed[0].len()) let crates: CrateStacks = (0..crates_transposed[0].len())
.map(|i| { .map(|i| {
crates_transposed crates_transposed
.iter() .iter()
.map(|items| items[i]) .map(|items| items[i])
.rev() .rev()
.filter_map(|item| item) .flatten()
.collect() .collect()
}) })
.collect(); .collect();

View File

@@ -26,7 +26,7 @@ pub fn process_part_2(input: &str) -> u32 {
directories directories
.values() .values()
.filter(|&size| *size >= wanted_space) .filter(|&size| *size >= wanted_space)
.map(|&size| size) .copied()
.min() .min()
.unwrap_or(0) .unwrap_or(0)
} }

View File

@@ -52,7 +52,7 @@ pub fn process_part_2(input: &str) -> usize {
fn parse_trees(input: &str) -> Vec<Vec<u8>> { fn parse_trees(input: &str) -> Vec<Vec<u8>> {
input input
.trim() .trim()
.split("\n") .split('\n')
.map(|i| i.chars().map(|c| c.to_digit(10).unwrap() as u8).collect()) .map(|i| i.chars().map(|c| c.to_digit(10).unwrap() as u8).collect())
.collect() .collect()
} }

View File

@@ -11,13 +11,13 @@ use nom::IResult;
pub fn process_part_1(input: &str) -> usize { pub fn process_part_1(input: &str) -> usize {
let (_, moves) = parse(input).unwrap(); let (_, moves) = parse(input).unwrap();
let visited = simulate_rope(moves, 2); let visited = simulate_rope(moves, 2);
return visited.len(); visited.len()
} }
pub fn process_part_2(input: &str) -> usize { pub fn process_part_2(input: &str) -> usize {
let (_, moves) = parse(input).unwrap(); let (_, moves) = parse(input).unwrap();
let visited = simulate_rope(moves, 10); let visited = simulate_rope(moves, 10);
return visited.len(); visited.len()
} }
fn simulate_rope(moves: Vec<(Direction, usize)>, rope_size: usize) -> BTreeSet<(i32, i32)> { fn simulate_rope(moves: Vec<(Direction, usize)>, rope_size: usize) -> BTreeSet<(i32, i32)> {