Ejemplo n.º 1
0
def get_seat_id(input_seat_position: Tuple[int, int]):
    """Get seat id."""
    return input_seat_position[0] * 8 + input_seat_position[1]


def part_one(input_data) -> int:
    """Print part one answer."""
    part_one_ans = max(map(get_seat_id, map(get_seat_position, input_data)))
    print(f"Part one ans: {part_one_ans}")
    return part_one_ans  # used in part 2


def part_two(part_one_ans: int, input_data) -> None:
    """Print part two answer."""
    seen = set()
    for seat_str in input_data:
        seat_pos = get_seat_position(seat_str)
        seat_id = get_seat_id(seat_pos)
        seen.add(seat_id)
    candidates = set(range(part_one_ans)) - seen
    for candidate in candidates:
        if (candidate + 1 in seen and candidate - 1 in seen):
            part_two_ans = candidate
    print(f"Part two ans: {part_two_ans}")


if __name__ == "__main__":
    dat = get_day_input(5)
    p1 = part_one(dat)
    part_two(p1, dat)
Ejemplo n.º 2
0
            print(f"Part one ans: {next_input * (2020 - next_input)}")
            break
        to_look_for.append(2020 - next_input)


def part_two(input_data) -> None:
    """Computes answer to part two."""
    to_look_for = []
    candidates = []
    for i in input_data:
        for j in input_data[1:]:
            if i + j < 2020:
                to_look_for.append(2020 - i - j)
        if i in to_look_for:
            candidates.append(i)
            if len(candidates) == 2:
                p2ans = (candidates[0] *
                         candidates[1] * (2020 -
                                          candidates[0] -
                                          candidates[1]
                                          )
                         )
                print(f"Part two ans: {p2ans}")
                break


if __name__ == "__main__":
    dat = [int(x) for x in get_day_input(1)]
    part_one(dat)
    part_two(dat)