Day 3 done and pedantic clippy clean up

This commit is contained in:
Dylan Thies
2023-12-03 20:48:26 -05:00
parent 3ac75e55bf
commit ecbaf8f9fe
7 changed files with 259 additions and 14 deletions

View File

@@ -1,9 +1,21 @@
#![warn(clippy::all, clippy::pedantic)]
use nom::{
self,
character::complete::{alphanumeric1, newline},
multi::separated_list1,
};
/// Day-1 part 1 of AC2023
///
/// # Arguments
/// - input the input for day1 as a string
///
/// # Panics
/// This panics whenever a number isn't present in a line of the input
///
/// # Errors
/// errors when can't parse the input
pub fn part1(input: &str) -> nom::IResult<&str, String> {
let (_, values) = parse_input(input)?;
println!("{values:?}");
@@ -11,7 +23,7 @@ pub fn part1(input: &str) -> nom::IResult<&str, String> {
"",
values
.iter()
.map(|v| v.first().unwrap() * 10 + v.last().unwrap())
.map(|v| v.first().expect("always at least one number") * 10 + v.last().expect("always atleast one number"))
.sum::<u32>()
.to_string(),
))

View File

@@ -1,9 +1,18 @@
#![warn(clippy::all, clippy::pedantic)]
/// Day 1 Part 2 of AOC2023
///
/// # Arguments
/// - puzzle input
///
/// # Panics
/// this panics if there is no numbers in a line
pub fn part2(input: &str) -> String {
let values = input.lines().map(parse_line).collect::<Vec<Vec<u32>>>();
println!("{values:?}");
values
.iter()
.map(|v| v.first().unwrap() * 10 + v.last().unwrap())
.map(|v| v.first().expect("There is always at least one number") * 10 + v.last().expect("there is always at least one number"))
.sum::<u32>()
.to_string()
}
@@ -33,7 +42,7 @@ fn parse_line(line: &str) -> Vec<u32> {
} else if reduced_line.starts_with("zero") {
Some(0)
} else {
reduced_line.chars().next().unwrap().to_digit(10)
reduced_line.chars().next().expect("there is alwayss a character").to_digit(10)
};
result