Blindly follow all clippy's decrees
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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)]
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub fn process_part_2(input: &str) -> u32 {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
return result;
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
11
src/day04.rs
11
src/day04.rs
@@ -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)?;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)> {
|
||||||
|
|||||||
Reference in New Issue
Block a user