1
0
mirror of https://gitlab.com/MisterBiggs/aoc-2023-rust.git synced 2025-06-15 14:36:50 +00:00

let clippy clean my code

This commit is contained in:
Anson Biggs 2023-12-03 15:03:33 -07:00
parent 37da94a246
commit 2eb390c17b

View File

@ -11,19 +11,21 @@ pub fn run() {
fn part1(calibration_input: &str) -> usize {
calibration_input
.split("\n")
.split('\n')
.map(|line| {
let digits = line.chars().filter(|c| c.is_digit(10)).collect::<String>();
let digits = line
.chars()
.filter(|c| c.is_ascii_digit())
.collect::<String>();
if digits.len() == 1 {
digits.parse::<usize>().unwrap() * 11
} else {
let tens = digits.chars().nth(0).unwrap().to_digit(10).unwrap();
let tens = digits.chars().next().unwrap().to_digit(10).unwrap();
let ones = digits.chars().last().unwrap().to_digit(10).unwrap();
(tens * 10 + ones) as usize
}
})
.into_iter()
.sum()
}
@ -41,7 +43,7 @@ fn part2(calibration_input: &str) -> usize {
];
calibration_input
.split("\n")
.split('\n')
.map(|line| {
let mut index_and_digit: Vec<(usize, usize)> = vec![];
@ -66,7 +68,6 @@ fn part2(calibration_input: &str) -> usize {
index_and_digit[0].1 * 10 + index_and_digit.last().unwrap().1
}
})
.into_iter()
.sum()
}