Skip to content
advent of code 2015

day 16

aunt sue

approach

every sue is parsed into a dict with only the properties that are listed for her, and the known readings sit in a target dict.

part 1 returns the sue whose listed properties all equal the target. part 2 changes the comparison for four of them: two must be strictly greater than the reading, two strictly lower, and the rest still have to match exactly. missing properties never rule anyone out.

the trick

only compare what each sue actually lists; anything missing is compatible.

python
def match2(sue, target):
    if "cats" in sue and sue["cats"] <= target["cats"]:
        return False
    if "trees" in sue and sue["trees"] <= target["trees"]:
        return False
    if "pomeranians" in sue and sue["pomeranians"] >= target["pomeranians"]:
        return False
    if "goldfish" in sue and sue["goldfish"] >= target["goldfish"]:
        return False
    for k in ["children", "samoyeds", "akitas", "cars", "perfumes"]:
        if k in sue and sue[k] != target[k]:
            return False
    return True