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()
.unwrap();
return result;
result
}
pub fn process_part_2(input: &str) -> u32 {

View File

@@ -37,7 +37,7 @@ pub fn process_part_1(input: &str) -> u32 {
.lines()
.map(|line| {
let moves = line
.split(" ")
.split(' ')
.map(|s| s.parse::<Move>().unwrap())
.collect::<Vec<_>>();
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::<Vec<_>>();
let moves = line.split(' ').collect::<Vec<_>>();
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)]

View File

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

View File

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

View File

@@ -50,7 +50,8 @@ struct Move {
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, _) = 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<&str>>, Vec<u32>, Vec<Mov
// ] => [ [D, A], [E, B], [C]
// (its transposed for pop() and push() magic :))
// 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| {
crates_transposed
.iter()
.map(|items| items[i])
.rev()
.filter_map(|item| item)
.flatten()
.collect()
})
.collect();

View File

@@ -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)
}

View File

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

View File

@@ -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)> {