cargo fmt
parent
e9f6c6e50d
commit
1da7a12927
|
@ -107,7 +107,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
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));
|
assert_eq!(result, Some(281));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,14 @@ fn parse(input: &str) -> Vec<Race> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part_one(input: &str) -> Option<u64> {
|
pub fn part_one(input: &str) -> Option<u64> {
|
||||||
Some(parse(input)
|
Some(
|
||||||
|
parse(input)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|race| race.winning_times().len() as u64)
|
.map(|race| race.winning_times().len() as u64)
|
||||||
.collect::<Vec<u64>>()
|
.collect::<Vec<u64>>()
|
||||||
.iter()
|
.iter()
|
||||||
.product())
|
.product(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part_two(input: &str) -> Option<u64> {
|
pub fn part_two(input: &str) -> Option<u64> {
|
||||||
|
|
|
@ -256,7 +256,10 @@ fn parse(input: &str) -> Vec<Hand> {
|
||||||
|
|
||||||
pub fn part_one(input: &str) -> Option<u32> {
|
pub fn part_one(input: &str) -> Option<u32> {
|
||||||
let mut sum: u64 = 0;
|
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();
|
hands.sort();
|
||||||
for (index, hand) in hands.iter().rev().enumerate() {
|
for (index, hand) in hands.iter().rev().enumerate() {
|
||||||
sum += hand.bid * (index as u64 + 1);
|
sum += hand.bid * (index as u64 + 1);
|
||||||
|
|
|
@ -38,7 +38,14 @@ fn next_number(s: &Seq) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part_one(input: &str) -> Option<u32> {
|
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 {
|
fn previous_number(s: &Seq) -> i32 {
|
||||||
|
@ -51,7 +58,14 @@ fn previous_number(s: &Seq) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part_two(input: &str) -> Option<u32> {
|
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)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -144,7 +144,6 @@ pub fn part_one(input: &str) -> Option<u64> {
|
||||||
Some(parts.iter().map(|p| filter_part(&rules, &p)).sum())
|
Some(parts.iter().map(|p| filter_part(&rules, &p)).sum())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn combinations(weights: [(u64, u64); 4]) -> u64 {
|
fn combinations(weights: [(u64, u64); 4]) -> u64 {
|
||||||
(0..4)
|
(0..4)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
Loading…
Reference in New Issue