Example #1
0
def input_data_to_seat_id_list(file_name: str) -> list[int]:
    codes: list[str] = get_input_data(file_name)
    seat_ids: list[int] = []
    for code in codes:
        row, column = decode(code)
        seat_ids.append(row * 8 + column)
    return seat_ids
Example #2
0
def simple_solution_part_1() -> int:
    passes, lower_limits, higher_limits, letters = get_input_data()
    valid_passwords: int = 0
    for i, passwd in enumerate(passes):
        if lower_limits[i] <= passwd.count(letters[i]) <= higher_limits[i]:
            valid_passwords += 1
    return valid_passwords
Example #3
0
def prepare_input(file_name: str) -> list[int]:
    numbers: list[int] = get_input_data(file_name)
    numbers.append(0)
    numbers.sort()
    numbers.append(numbers[-1] + 3)
    logger.debug(numbers)
    logger.debug(len(numbers))
    return numbers
Example #4
0
def solution_part_2(file_name: str, window_size: int) -> int:
    goal: int = solution_part_1(file_name, window_size)
    numbers: list[int] = get_input_data(file_name)
    for i in range(2, len(numbers) + 1):
        for j in range(0, len(numbers) - i + 1):
            if sum(numbers[j:j + i]) == goal:
                return max(numbers[j:j + i]) + min(numbers[j:j + i])
    return 0
Example #5
0
def simple_solution_part_2() -> int:
    passes, lower_limits, higher_limits, letters = get_input_data()
    valid_passwords: int = 0
    for i, passwd in enumerate(passes):
        if (passwd[lower_limits[i] - 1]
                == letters[i]) ^ (passwd[higher_limits[i] - 1] == letters[i]):
            valid_passwords += 1
    return valid_passwords
Example #6
0
def solution_part_2(file_name: str) -> int:
    bag_connections: dict[str, list[(int, str)]] = get_input_data(file_name)
    backlog: list[(int, str)] = list(bag_connections["shiny gold"])
    current_bag: (int, str)
    bags_needed: int = 0
    while len(backlog) != 0:
        current_bag = backlog.pop(0)
        bags_needed += current_bag[0]
        backlog.extend(
            multiply_connections(current_bag[0],
                                 bag_connections[current_bag[1]]))
    return bags_needed
Example #7
0
def solution_part_1(file_name: str, window_size: int) -> int:
    numbers: list[int] = get_input_data(file_name)
    logger.debug(numbers)
    window: set[int]
    for i in range(0, len(numbers) - window_size):
        window = set(numbers[i:i + window_size])
        goal = numbers[i + window_size]
        logger.debug(f"Window: {window}, Goal: {goal}")
        if find_sum_in_window(window, goal):
            continue
        return goal
    return 0
Example #8
0
def simple_solution_part_1(slope: tuple[int, int]) -> int:
    grid: list[list[str]] = get_input_data()
    height: int = len(grid)
    width = len(grid[0])
    pos: list[int, int] = [0, 0]
    tree_count: int = 0
    while pos[0] < height:
        if grid[pos[0]][pos[1]] == "#":
            tree_count += 1
        pos[0] += slope[1]
        pos[1] = (pos[1] + slope[0]) % width
    return tree_count
Example #9
0
def solution_part_1(file_name: str) -> int:
    bag_connections: dict[str, list[(int, str)]] = get_input_data(file_name)
    rev_bag_connections: dict[str, set[str]] = invert_dict(bag_connections)
    for conn in rev_bag_connections:
        logger.debug(f"Key: {conn}, vales: {rev_bag_connections[conn]}")
    backlog: list[str] = list(rev_bag_connections["shiny gold"])
    visited: set[str] = {"shiny gold"}
    current_col: str
    while len(backlog) != 0:
        current_col = backlog.pop(0)
        visited.add(current_col)
        if current_col in rev_bag_connections:
            backlog.extend(rev_bag_connections[current_col])
    return len(visited) - 1
Example #10
0
def solution_part_2(file_name: str) -> int:
    commands: list[(str, int)] = get_input_data(file_name)
    for index, command in enumerate(commands):
        if command[0] == "acc":
            continue
        if command[0] == "nop":
            commands_copy: list[(str, int)] = commands.copy()
            commands_copy[index] = ("jmp", command[1])
            loop_result: (bool, int) = loop_through_commands(commands_copy)
            if loop_result[0]:
                return loop_result[1]
            continue
        if command[0] == "jmp":
            commands_copy: list[(str, int)] = commands.copy()
            commands_copy[index] = ("nop", command[1])
            loop_result: (bool, int) = loop_through_commands(commands_copy)
            if loop_result[0]:
                return loop_result[1]
            continue
    return -1
Example #11
0
def solution_part_1(file_name: str) -> int:
    commands: list[(str, int)] = get_input_data(file_name)
    return loop_through_commands(commands)[1]
Example #12
0
def simple_solution_part_1() -> int:
    passports = get_input_data("inputData.txt")
    valid: int = 0
    for passport in passports:
        valid += int(passport.valid())
    return valid
Example #13
0
def simple_solution_part_2_tests(file_name: str) -> int:
    passports = get_input_data(file_name)
    valid: int = 0
    for passport in passports:
        valid += int(passport.valid_part_2())
    return valid