Ejemplo n.º 1
0
Archivo: 3.py Proyecto: vicjor/aoc
def main():
    start = perf_counter()  # Start time

    bits = file_reader("data/input3'.txt")

    print("## PART 1 ##")
    # Gamma rate represented as binary
    gamma_rate_bin = gamma_rate(bits)

    # Epsilon rate represented as integer
    epsilon_rate_int = epsilon_rate(gamma_rate_bin)

    # Gamma rate represented as integer
    gamma_rate_int = int(gamma_rate_bin, 2)

    power_consumption = epsilon_rate_int * gamma_rate_int
    print(f"Power consumption of submarine: {power_consumption}\n")  # 3959450

    print("## PART 2 ##")

    o_2 = oxygen_generator_rating(bits)
    co_2 = co2_scrubber_rating(bits)
    life_support_rating = o_2 * co_2
    print(f"Life support rating: {life_support_rating}.\n")  # 7440311

    end = perf_counter()  # End time
    time = end - start  # Total runtime
    print(f"Total runtime: {time} seconds.")
Ejemplo n.º 2
0
def main():
    start = perf_counter()  # Start time
    print("## PART 1 ##")
    data = file_reader("data/input4.txt")
    numbers = [int(x) for x in data[0].split(",")]
    bingo_board_numbers = list(
        filter(lambda x: x != '', [x for x in data[1::]]))
    bingo_boards = create_bingo_boards(bingo_board_numbers)
    board, numbers_drawn = play_bingo(bingo_boards, numbers)
    final_score = calculate_final_score(board, numbers_drawn)
    print(f"Final score: {final_score}.\n")  # 35670

    print("## PART 2 ##")

    # play_bingo_3(bingo_boards, numbers)

    board_2, numbers_drawn_2 = play_bingo_2(bingo_boards, numbers)

    winning_number = numbers_drawn_2[-1]
    winning_number_index = numbers_drawn_2.index(winning_number)
    print(f"Winning number: {winning_number}, index {winning_number_index}")
    print("Last board: ", board_2)
    final_score_2 = calculate_final_score(board_2, numbers_drawn_2)
    print(numbers_drawn_2)
    # 25110 too high, 15928 too low. 23892 wrong.
    print(f"Final score: {final_score_2}.\n")

    end = perf_counter()  # End time
    time = end - start  # Total runtime
    print(f"Total runtime: {time} seconds.")
Ejemplo n.º 3
0
Archivo: 7.py Proyecto: vicjor/aoc
def main():
    start = perf_counter()  # Start time

    data = file_reader("data/input7.txt")
    positions = [int(x) for x in data[0].split(",")]
    print(cheapest_alignment_2(positions))  # 328187

    end = perf_counter()  # End time
    time = end - start  # Total runtime
    print(f"Total runtime: {time} seconds.")
Ejemplo n.º 4
0
def main():
    start = perf_counter()  # Start time

    notes = file_reader("data/input8.txt")
    print(f"Part 1: {part1(notes)}")
    print(f"Part 2: {part2(notes)}")  # 1016804

    end = perf_counter()  # End time
    time = end - start  # Total runtime
    print(f"Total runtime: {time} seconds.")
Ejemplo n.º 5
0
def main():
    heightmap = file_reader("data/input9.txt")
    lowpoints = find_lowpoints(heightmap)
    risk_level = get_risk_level(lowpoints)
    print("## PART 1 ##")  # 603.
    print(f"The sum of the risk level in the heightmap is {risk_level}.\n")

    print("## PART 2 ##")  # 786780.
    basins = find_basins(lowpoints, heightmap)
    basins_multiplied = multiply_basins(basins)
    print(f"Three largest basins {basins} multiplied is {basins_multiplied}.\n")
Ejemplo n.º 6
0
Archivo: 12.py Proyecto: vicjor/aoc
def main():
    data = file_reader("data/input12.txt")
    G = create_graph(data)
    number_of_paths = len(find_all_paths(G, "start", "end"))
    number_of_paths_2 = len(find_all_paths(G, "start", "end", pt_2=True))
    print("## PART 1 ##")
    print(f"{number_of_paths} paths from start to end.")  # 3761
    print("## PART 2 ##")
    # 99138
    print(
        f"{number_of_paths_2} paths when allowing a single small cave to be visited twice."
    )
Ejemplo n.º 7
0
Archivo: 13.py Proyecto: vicjor/aoc
def main():
    data = file_reader("data/input13.txt")
    coordinates, instructions = prepare_data(data)
    grid = get_grid(coordinates)
    grid = fold(grid, 655, horizontal=False)
    dots = count_dots(grid)

    print("## PART 1 ##")
    print(f"{dots} visible dots after folding vertical across x = 655.\n")  # 765

    print("## PART 2## ")
    folded_grid = perform_instructions(grid, instructions)
    print_grid(folded_grid)
Ejemplo n.º 8
0
Archivo: 2.py Proyecto: vicjor/aoc
def main():
    commands = file_reader("data/input2.txt")
    horizontal, depth = interpret_commands(commands)
    answer = horizontal * depth
    print("## PART 1 ##")
    print(
        f"The final answer is {answer} ({horizontal} horizontal * {depth} depth.)\n"
    )
    print("## PART 2 ##")
    horizontal_2, depth_2 = interpret_commands_2(commands)
    answer_2 = horizontal_2 * depth_2
    print(
        f"The final answer is {answer_2} ({horizontal_2} horizontal * {depth_2} depth.)\n"
    )
Ejemplo n.º 9
0
def main():
    start = perf_counter()  # Start time

    lines = file_reader("data/input5.txt")
    coordinates = aggregate_overlaps(lines)
    coordinates_2 = aggregate_overlaps(lines, True)
    overlaps = count_overlaps(coordinates)
    overlaps_2 = count_overlaps(coordinates_2)
    print(f"Number of points with minimum two overlaps: {overlaps}")  # 5585
    print(
        f"Number of points with minimum two overlaps including diagonals: {overlaps_2}")  # 17193
    end = perf_counter()  # End time
    time = end-start  # Total runtime
    print(f"\nTotal runtime: {time} seconds.")
Ejemplo n.º 10
0
Archivo: 6.py Proyecto: vicjor/aoc
def main():
    start = perf_counter()  # Start time

    data = file_reader("data/input6.txt")
    initial_state = [int(x) for x in data[0].split(",")]
    print("## PART 1 ##")
    part1 = simulate(initial_state)
    print(f"There are {part1} lanternfish after 80 days.\n")  # 373378

    print("## PART 2 ##")
    part2 = simulate_2(initial_state)
    print(f"There are {part2} lanternfish after 256 days.")  # 1786011142253081
    end = perf_counter()  # End time
    time = end-start  # Total runtime
    print(f"\nTotal runtime: {time} seconds.")
Ejemplo n.º 11
0
def main():

    data = file_reader("data/input.txt")
Ejemplo n.º 12
0
Archivo: 10.py Proyecto: vicjor/aoc
def main():
    lines = file_reader("data/input10.txt")
    print("Total score: ", syntax_error_score(lines))
    incomplete_lines = [x for x in lines if get_invalid_character(x) == None]
    middle_score = get_middle_score(incomplete_lines)
    print(f"Middle score: {middle_score}")