def _parse(inputs: tuple[str]) -> int: blocks = my_aocd.to_blocks(inputs) algorithm = blocks[0][0] data = {(r, c) for r, line in enumerate(blocks[1]) for c, ch in enumerate(line) if ch == LIGHT} return ImageEnhancement(algorithm, data)
def _parse(inputs: tuple[str]) -> tuple[dict, str]: blocks = my_aocd.to_blocks(inputs) replacements = defaultdict(list[str]) for line in blocks[0]: split = line.split(" => ") replacements[split[0]].append(split[1]) assert len(blocks[1]) == 1 return replacements, blocks[1][0]
def _parse(inputs: tuple[str]): blocks = my_aocd.to_blocks(inputs) rules = dict() for input_ in blocks[0]: splits = input_.split(": ") splits[1] = splits[1].replace("\"", "") rules[int(splits[0])] = splits[1] messages = blocks[1] return rules, messages
def _parse(inputs: tuple[str]) -> set[Position, tuple[Fold]]: blocks = my_aocd.to_blocks(inputs) positions = { Position.of(*[int(_) for _ in line.split(',')]) for line in blocks[0] } folds = list[Fold]() for line in blocks[1]: axis, value = line[len("fold along "):].split('=') folds.append(Fold(axis == 'x', int(value))) return positions, tuple(folds)
def _parse(inputs: tuple[str]) -> list[Tile]: blocks = my_aocd.to_blocks(inputs) tiles = list[Tile]() for block in blocks: grid = list[str]() for line in block: if line.startswith("Tile"): idx = int(line[len("Tile") + 1:-1]) else: grid.append(line) tiles.append(Tile(idx, grid)) return tiles
def _parse(inputs: tuple[str]) -> Players: blocks = my_aocd.to_blocks(inputs) pl1 = [] for i, line in enumerate(blocks[0]): if i == 0: continue pl1.append(int(line)) pl2 = [] for i, line in enumerate(blocks[1]): if i == 0: continue pl2.append(int(line)) return Players(pl1, pl2)
def _parse(inputs: tuple[str]) -> tuple[list[int], list[Board]]: blocks = my_aocd.to_blocks(inputs) draws = [int(_) for _ in blocks[0][0].split(',')] boards = [Board(_) for _ in blocks[1:]] return draws, boards
def _normalize(inputs: tuple[str]) -> list[str]: return [ " ".join(line for line in block) for block in my_aocd.to_blocks(inputs) ]
def parse(inputs: tuple[str]): blocks = my_aocd.to_blocks(inputs) rules = parse_rules(blocks[0]) my_ticket = parse_tickets(blocks[1])[0] tickets = parse_tickets(blocks[2]) return rules, my_ticket, tickets