""" Day Seven - BFS / DFS search """ import utils if __name__ == '__main__': lines = utils.read_strings_from_lines("in/day_07.txt") bags = {} # parse input for line in lines: sp = line.split("contain") if "no other" in sp[1]: bag_name_info = sp[0].split() bag_name = f"{bag_name_info[0]} {bag_name_info[1]}" bags[bag_name] = [] else: first_info = sp[0] second_info = sp[1] bag_name_info = first_info.split() bag_name = f"{bag_name_info[0]} {bag_name_info[1]}" bags[bag_name] = [] inside_info = second_info.split(",")
""" Day Six - Sets (intersection) """ import utils if __name__ == '__main__': lines = utils.read_strings_from_lines("in/day_06.txt", strip=False) lines.append("\n") groups = [] current_people = [] for line in lines: if line == "\n": groups.append(set.intersection(*current_people)) current_people = [] else: answers = line.strip() person = set() for character in answers: person.add(character) current_people.append(person) total = 0 for group in groups: print(group) total += len(group)