Day 15 part 2.

This commit is contained in:
2024-01-14 11:25:36 +01:00
parent 63552704fd
commit 7aa9f359c8

View File

@@ -58,10 +58,42 @@ fn part1(input: &[Ingredient]) -> i32 {
scores.into_iter().max().unwrap() scores.into_iter().max().unwrap()
} }
// #[aoc(day15, part2)] #[aoc(day15, part2)]
// fn part2(input: &[Ingredient]) -> String { fn part2(input: &[Ingredient]) -> i32 {
// todo!() let mut scores = HashSet::new();
// } for a in 0i32..=100 {
for b in 0i32..=(100 - a) {
for c in 0i32..=(100 - a - b) {
for d in 0i32..=(100 - a - b - c) {
if a + b + c + d != 100 {
continue;
}
if a * input[0].calories + b * input[1].calories + c * input[2].calories + d * input[3].calories != 500 {
continue;
}
let mut capacity = a * input[0].capacity + b * input[1].capacity + c * input[2].capacity + d * input[3].capacity;
let mut durability = a * input[0].durability + b * input[1].durability + c * input[2].durability + d * input[3].durability;
let mut flavor = a * input[0].flavor + b * input[1].flavor + c * input[2].flavor + d * input[3].flavor;
let mut texture = a * input[0].texture + b * input[1].texture + c * input[2].texture + d * input[3].texture;
if capacity < 0 {
capacity = 0;
}
if durability < 0 {
durability = 0;
}
if flavor < 0 {
flavor = 0;
}
if texture < 0 {
texture = 0;
}
scores.insert(capacity * durability * flavor * texture);
}
}
}
}
scores.into_iter().max().unwrap()
}
struct Ingredient { struct Ingredient {
capacity: i32, capacity: i32,
@@ -70,18 +102,3 @@ struct Ingredient {
texture: i32, texture: i32,
calories: i32, calories: i32,
} }
//
// #[cfg(test)]
// mod tests {
// use super::*;
//
// #[test]
// fn part1_example() {
// assert_eq!(part1(&parse("<EXAMPLE>")), "<RESULT>");
// }
//
// #[test]
// fn part2_example() {
// assert_eq!(part2(&parse("<EXAMPLE>")), "<RESULT>");
// }
// }