1
0
Fork 0

cargo fmt

main
Andrew Coleman 2024-02-21 12:59:51 -05:00
parent e9f6c6e50d
commit 1da7a12927
5 changed files with 31 additions and 11 deletions

View File

@ -107,7 +107,9 @@ mod tests {
#[test]
fn test_part_two() {
let result = part_two(&advent_of_code::template::read_file("examples", DAY, 2));
let result = part_two(&advent_of_code::template::read_file_part(
"examples", DAY, 2,
));
assert_eq!(result, Some(281));
}
}

View File

@ -39,12 +39,14 @@ fn parse(input: &str) -> Vec<Race> {
}
pub fn part_one(input: &str) -> Option<u64> {
Some(parse(input)
Some(
parse(input)
.iter()
.map(|race| race.winning_times().len() as u64)
.collect::<Vec<u64>>()
.iter()
.product())
.product(),
)
}
pub fn part_two(input: &str) -> Option<u64> {

View File

@ -256,7 +256,10 @@ fn parse(input: &str) -> Vec<Hand> {
pub fn part_one(input: &str) -> Option<u32> {
let mut sum: u64 = 0;
let mut hands = parse(input).iter().map(|h| h.clone()).collect::<Vec<Hand>>();
let mut hands = parse(input)
.iter()
.map(|h| h.clone())
.collect::<Vec<Hand>>();
hands.sort();
for (index, hand) in hands.iter().rev().enumerate() {
sum += hand.bid * (index as u64 + 1);

View File

@ -38,7 +38,14 @@ fn next_number(s: &Seq) -> i32 {
}
pub fn part_one(input: &str) -> Option<u32> {
Some(parse(input).iter().map(|s| next_number(&s)).sum::<i32>().try_into().unwrap())
Some(
parse(input)
.iter()
.map(|s| next_number(&s))
.sum::<i32>()
.try_into()
.unwrap(),
)
}
fn previous_number(s: &Seq) -> i32 {
@ -51,7 +58,14 @@ fn previous_number(s: &Seq) -> i32 {
}
pub fn part_two(input: &str) -> Option<u32> {
Some(parse(input).iter().map(|s| previous_number(&s)).sum::<i32>().try_into().unwrap())
Some(
parse(input)
.iter()
.map(|s| previous_number(&s))
.sum::<i32>()
.try_into()
.unwrap(),
)
}
#[cfg(test)]

View File

@ -144,7 +144,6 @@ pub fn part_one(input: &str) -> Option<u64> {
Some(parts.iter().map(|p| filter_part(&rules, &p)).sum())
}
fn combinations(weights: [(u64, u64); 4]) -> u64 {
(0..4)
.into_iter()