Function aoc::y15d16::y15d16

source ·
pub fn y15d16(input: &str, part: u32) -> u32
Expand description

The solution for the day sixteen challenge.

Starting with the input as a string and the part we’re solving (which only affects some of the comparisons that we do to find the real aunt sue) we parse the input into AuntSue objects and then try to find out if we have the one we’re looking for. In theory we could optimize this further by not creating objects but running the comparison as we try to check each field, but I don’t think that it’s worth it. Leaving it as-is creates a cleaner, easier-to-reason-about solution. If we get 0 back (which is not a valid Aunt Sue) then it means that we exhausted the input list of Sues and were unable to find the one that we were looking for.

§Example

// probably read this from the input file...
let input = concat!(
    "Sue 1: goldfish: 5, cars: 2, samoyeds: 2\n",
    "Sue 2: goldfish: 4, cars: 2, samoyeds: 2",
);
assert_eq!(y15d16(input, 1), 1);
assert_eq!(y15d16(input, 2), 2);