Day 16 part 2.

This commit is contained in:
2024-06-23 10:50:36 +02:00
parent 6b6bdff5d3
commit 4056898a87

View File

@@ -46,10 +46,54 @@ perfumes: 1";
sue.0 + 1 sue.0 + 1
} }
// #[aoc(day16, part2)] #[aoc(day16, part2)]
// fn part2(input: &[Ingredient]) -> i32 { fn part2(input: &[Sue]) -> usize {
// 0 let exact = "children: 3
// } samoyeds: 2
akitas: 0
vizslas: 0
cars: 2
perfumes: 1";
let exact = foo(exact);
let gt = "cats: 7
trees: 3";
let gt = foo(gt);
let lt = "pomeranians: 3
goldfish: 5";
let lt = foo(lt);
let sues: Vec<_> = input.iter()
.enumerate()
.filter(|(_index, sue)| {
exact.iter()
.all(|(property, _)| {
!sue.contains_key(property) || exact.get(property) == sue.get(property)
})
&& gt.iter()
.all(|(property, _)| {
!sue.contains_key(property) || gt.get(property).unwrap() < sue.get(property).unwrap()
})
&& lt.iter()
.all(|(property, _)| {
!sue.contains_key(property) || lt.get(property).unwrap() > sue.get(property).unwrap()
})
})
.collect();
dbg!(&sues);
sues[0].0 + 1
}
// 56 wrong
// 213 too low
fn foo(exact: &str) -> Sue {
let exact: Sue = exact.split("\n")
.map(|line| {
let (name, count) = line.split_once(": ").unwrap();
(name.to_string(), count.parse().unwrap())
}).collect();
exact
}
type Sue = HashMap<String, u8>; type Sue = HashMap<String, u8>;