Пример #1
0
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)
Пример #2
0
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]
Пример #3
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
Пример #4
0
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)
Пример #5
0
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
Пример #6
0
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)
Пример #7
0
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
Пример #8
0
def _normalize(inputs: tuple[str]) -> list[str]:
    return [
        " ".join(line for line in block) for block in my_aocd.to_blocks(inputs)
    ]
Пример #9
0
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