diff --git a/src/day16.rs b/src/day16.rs index ca53395..6006720 100644 --- a/src/day16.rs +++ b/src/day16.rs @@ -46,10 +46,54 @@ perfumes: 1"; sue.0 + 1 } -// #[aoc(day16, part2)] -// fn part2(input: &[Ingredient]) -> i32 { -// 0 -// } +#[aoc(day16, part2)] +fn part2(input: &[Sue]) -> usize { + 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;