Day 16: Aunt Sue

Day 16.1


In [1]:
ticker_tape = {'children': 3,
               'cats': 7,
               'samoyeds': 2,
               'pomeranians': 3,
               'akitas': 0,
               'vizslas': 0,
               'goldfish': 5,
               'trees': 3,
               'cars': 2,
               'perfumes': 1}

In [12]:
import csv

def parse_aunts(input_path):
    auntsues = {}
    with open(input_path, 'rt') as f_input:
        csv_reader = csv.reader(f_input, delimiter=' ')
        for l in csv_reader:
            auntsues[int(l[1].rstrip(':'))] = {l[2].rstrip(':'): int(l[3].rstrip(',')), 
                                               l[4].rstrip(':'): int(l[5].rstrip(',')), 
                                               l[6].rstrip(':'): int(l[7].rstrip(','))}
    return auntsues

In [14]:
auntsues = parse_aunts('inputs/input16.txt')

In [15]:
def ticker_consistent(suedict):
    for k, v in suedict.items():
        if ticker_tape[k] != v:
            return False
    return True

def which_auntsue():
    outcome = {}
    for k, suedict in auntsues.items():
        outcome[k] = ticker_consistent(suedict)
    for i, b in outcome.items():
        if b: print(i, b)

In [16]:
which_auntsue()


213 True

Day 16.2

In particular, the cats and trees readings indicates that there are greater than that many (...), while the pomeranians and goldfish readings indicate that there are fewer than that many (...).

In [27]:
def new_ticker_consistent(suedict):
    for k, v in suedict.items():
        if k in ['cats', 'trees']: 
            if v <= ticker_tape[k]:
                return False
        elif k in ['pomeranians', 'goldfish']:
            if v >= ticker_tape[k]:
                return False
        elif ticker_tape[k] != v:
            return False
    return True

In [28]:
def new_which_auntsue():
    outcome = {}
    for k, suedict in auntsues.items():
        outcome[k] = new_ticker_consistent(suedict)
    for i, b in outcome.items():
        if b: print(i, b)

In [29]:
new_which_auntsue()


323 True