def parse_input(filename: str) -> dict: inp = read_raw(get_path(__file__, filename)) splitted = inp.split("\n\n") tiles = [] for tile in splitted: lines = tile.split("\n") id = int(lines[0].split(" ")[1].rstrip(":")) tile = Tile(id, [[x for x in l] for l in lines[1:]]) tile.calc_versions() tiles.append(tile) return tiles
def part_one(filename: str) -> int: lines = read_raw(get_path(__file__, filename)) pports = lines.split("\n\n") valid_pports = [] for p in pports: valid_fields = 0 for f in p.replace("\n", " ").split(): k, v = f.split(":") valid_fields += k in checks.keys() if valid_fields >= 7: valid_pports.append(p) return len(valid_pports)
def parse_input(self, filename): lines = read_raw(filename) splitted = lines.split("\n\n") messages = splitted[1].split("\n") rules = {} for rule in splitted[0].split("\n"): key, r = rule.split(":") val = str(r).replace('"', "").strip() if val.isalpha(): rules[int(key)] = (0, [val]) else: rules[int(key)] = (1, [x.strip() for x in r.split("|")]) return rules, messages
def part_two(filename: str) -> int: lines = read_raw(get_path(__file__, filename)).split("\n\n") return sum([common_letters(l) for l in lines])
def part_one(filename: str) -> int: lines = read_raw(get_path(__file__, filename)).split("\n\n") return sum([len(set(line.replace("\n", ""))) for line in lines])
def part_one(filename: str) -> int: n = read_raw(get_path(__file__, filename)) return calc_one(n.strip("\n"), 100)