Day 16 part 2.
This commit is contained in:
52
src/day16.rs
52
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<String, u8>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user