My 2025 Attempts

Day 1

Part 1

import os
import numpy as np

input = open(os.path.join("2025", "day_01", "input_day01.txt")).read().splitlines()

def part1(input):
    input = [x.replace("L", "-") if "L" in x else x.replace("R", "+") for x in input]

    rotations = 50 + np.cumsum([int(x) for x in input])

    dial_number = [
        x - (int(x / 100) * 100) if (np.abs(x) > 99) else x for x in rotations
    ]

    n_zero = int(sum([x + 1 for x in dial_number if x == 0]))

    return n_zero


print(part1(input))
1195
0.005 seconds elapsed

Part 2

import os
import numpy as np

input = open(os.path.join("2025", "day_01", "input_day01.txt")).read().splitlines()

def part2(input):
    instruction = [
        int(x.replace("L", "-")) if "L" in x else int(x.replace("R", "+"))
        for x in input
    ]

    dial_number = 50
    n_zero = 0
    for x in instruction:
        if x > 0:
            n_zero += (dial_number + np.abs(x)) // 100
            dial_number = (dial_number + np.abs(x)) % 100
        else:
            if dial_number == 0:
                n_zero += np.abs(x) // 100
            elif np.abs(x) >= dial_number:
                n_zero += (np.abs(x) - dial_number) // 100 + 1
            dial_number = (dial_number - np.abs(x)) % 100

    return int(n_zero)


print(part2(input))
6770
0.006 seconds elapsed

Day 2

Part 1

import os

input = open(os.path.join("2025", "day_02", "input_day02.txt")).read().split(",")

def part1(input):
    id_ranges = [[int(x) for x in strings.split("-")] for strings in input]

    valid_ids = []
    for min_val, max_val in id_ranges:
        values_in_range = [str(x) for x in list(range(min_val, max_val + 1))]
        valid_ids = valid_ids + [
            x for x in values_in_range if x[: int(len(x) / 2)] == x[int(len(x) / 2) :]
        ]

    sum_of_valid = sum([int(x) for x in valid_ids])

    return sum_of_valid


print(part1(input))
44854383294
0.287 seconds elapsed

Part 2

import os

input = open(os.path.join("2025", "day_02", "input_day02.txt")).read().split(",")

def part2(input):
    id_ranges = [[int(x) for x in strings.split("-")] for strings in input]

    valid_ids = []
    for min_val, max_val in id_ranges:
        values_in_range = [str(x) for x in list(range(min_val, max_val + 1))]
        valid_ids = valid_ids + [x for x in values_in_range if x in (x * 2)[1:-1]]

    sum_of_valid = sum([int(x) for x in valid_ids])

    return sum_of_valid


print(part2(input))
55647141923
0.244 seconds elapsed

Day 3

Part 1

import os

input = open(os.path.join("2025", "day_03", "input_day03.txt")).read().splitlines()

def part1(input):
    total_joltage = 0
    for bank in input:
        list_of_digits = [int(x) for x in bank]

        max_joltage = 0
        for i in range(len(list_of_digits)):
            for j in range(i + 1, len(list_of_digits)):
                max_joltage = max(
                    max_joltage, 10 * list_of_digits[i] + list_of_digits[j]
                )

        total_joltage += max_joltage

    return total_joltage


print(part1(input))
17179
0.029 seconds elapsed

Part 2

import os

input = open(os.path.join("2025", "day_03", "input_day03.txt")).read().splitlines()

def part2(input):
    total_joltage = 0
    for bank in input:
        list_of_digits = [int(x) for x in bank]

        joltage = [[0 for _ in range(12 + 1)] for _ in range(len(list_of_digits) + 1)]

        for i in range(len(list_of_digits)):
            for j in range(12 + 1):
                joltage[i + 1][j] = max(joltage[i + 1][j], joltage[i][j])
                if j < 12:
                    joltage[i + 1][j + 1] = max(
                        joltage[i + 1][j + 1], 10 * joltage[i][j] + list_of_digits[i]
                    )

            total_joltage += joltage[len(list_of_digits)][12]

    return total_joltage


print(part2(input))
170025781683941
0.037 seconds elapsed

Day 4

Part 1

import os

input = open(os.path.join("2025", "day_04", "input_day04.txt")).read().splitlines()
input = [list(x) for x in input]

def get_neighbors(coordinates_of_interest, diagram):
    x, y = coordinates_of_interest
    neighbors = []
    if x < len(diagram[0]) - 1:
        neighbors.append(diagram[y][x + 1])
    if x > 0:
        neighbors.append(diagram[y][x - 1])
    if y < len(diagram) - 1:
        neighbors.append(diagram[y + 1][x])
    if y > 0:
        neighbors.append(diagram[y - 1][x])
    if x < len(diagram[0]) - 1 and y > 0:
        neighbors.append(diagram[y - 1][x + 1])
    if x > 0 and y > 0:
        neighbors.append(diagram[y - 1][x - 1])
    if x < len(diagram[0]) - 1 and y < len(diagram) - 1:
        neighbors.append(diagram[y + 1][x + 1])
    if x > 0 and y < len(diagram) - 1:
        neighbors.append(diagram[y + 1][x - 1])

    n_rolls_inaccessible = len([x for x in neighbors if x == "@"])

    return n_rolls_inaccessible


def part1(input):
    solution = 0
    for y in range(len(input)):
        for x in range(len(input[0])):
            if (input[y][x] == "@") & (get_neighbors([x, y], input) < 4):
                solution += 1

    return solution


print(part1(input))
1376
0.013 seconds elapsed

Day 5

Part 1

import os

input = open(os.path.join("2025", "day_05", "input_day05.txt")).read()

def part1(input):
    ing_ranges, ingr_ids = input.split("\n\n")

    ing_ranges = [[int(y) for y in x.split("-")] for x in ing_ranges.splitlines()]

    ingr_ids = [int(x) for x in ingr_ids.splitlines()]

    fresh_ings = len(
        set([x for x in ingr_ids for y in ing_ranges if (x >= y[0]) & (x <= y[1])])
    )

    return fresh_ings


print(part1(input))
773
0.007 seconds elapsed

Part 2

import os

input = open(os.path.join("2025", "day_05", "input_day05.txt")).read()

def part2(input):
    ing_ranges = input.split("\n\n")[0]
    ing_ranges = sorted(
        [[int(y) for y in x.split("-")] for x in ing_ranges.splitlines()]
    )

    fresh_ing_ids = []
    for min_val, max_val in ing_ranges:
        if not fresh_ing_ids or (fresh_ing_ids[-1][1] < min_val - 1):
            fresh_ing_ids = fresh_ing_ids + [[min_val, max_val]]
        else:
            fresh_ing_ids[-1][1] = max(fresh_ing_ids[-1][1], max_val)

    num_fresh_ings_ids = sum(
        max_val - min_val + 1 for min_val, max_val in fresh_ing_ids
    )

    return num_fresh_ings_ids


print(part2(input))
332067203034711
0.002 seconds elapsed

Day 6

Part 1

import os
import math

input = open(os.path.join("2025", "day_06", "input_day06.txt")).read().splitlines()

def part1(input):
    values = [[int(y) for y in x.split(" ") if len(y) > 0] for x in input[:-1]]
    operators = [x for x in input[-1].split(" ") if len(x) > 0]

    assert len(operators) == len(values[0])

    answers = []
    for i in range(len(values[0])):
        values_of_interest = [values[i] for values in values]
        answers = answers + [
            (
                sum(values_of_interest)
                if operators[i] == "+"
                else math.prod(values_of_interest)
            )
        ]

    grand_total = sum(answers)

    return grand_total


print(part1(input))
4693419406682
0.003 seconds elapsed

Part 2

import os
import math

input = open(os.path.join("2025", "day_06", "input_day06.txt")).read().splitlines()

def part2(input):

    rev_values = [x[::-1] for x in input]

    grand_total = 0
    transposed_values = []
    for x in zip(*rev_values):
        try:
            transposed_values = transposed_values + [int("".join(x[:-1]))]
        except ValueError:
            continue
        if x[-1] == "+":
            grand_total += sum(transposed_values)
            transposed_values = []
        elif x[-1] == "*":
            grand_total += math.prod(transposed_values)
            transposed_values = []

    return grand_total


print(part2(input))
9029931401920
0.003 seconds elapsed

Day 7

Accidentally solved part 2 as part of part 1 processing

Part 1

import os

input = open(os.path.join("2025", "day_07", "input_day07.txt")).read().splitlines()

def process_tachyon_manifold_diagram(input):
    width = len(input[0])
    beams = [0] * width
    beams[input[0].index("S")] = 1

    n_splits = 0
    for manifold_row in input[1:]:
        for manifold_col in range(width):
            if manifold_row[manifold_col] == "^" and beams[manifold_col] > 0:
                beams[manifold_col - 1] += beams[manifold_col]
                beams[manifold_col + 1] += beams[manifold_col]
                n_splits += 1
                beams[manifold_col] = 0

    return n_splits, beams

def part1(input):
    n_splits, _ = process_tachyon_manifold_diagram(input)

    return n_splits


print(part1(input))
1553
0.002 seconds elapsed

Part 2

import os

input = open(os.path.join("2025", "day_07", "input_day07.txt")).read().splitlines()

def process_tachyon_manifold_diagram(input):
    width = len(input[0])
    beams = [0] * width
    beams[input[0].index("S")] = 1

    n_splits = 0
    for manifold_row in input[1:]:
        for manifold_col in range(width):
            if manifold_row[manifold_col] == "^" and beams[manifold_col] > 0:
                beams[manifold_col - 1] += beams[manifold_col]
                beams[manifold_col + 1] += beams[manifold_col]
                n_splits += 1
                beams[manifold_col] = 0

    return n_splits, beams

def part2(input):
    _, beams = process_tachyon_manifold_diagram(input)

    n_timelines = sum(beams)

    return n_timelines


print(part2(input))
15811946526915
0.002 seconds elapsed

Day 8

Day 9

Part 1

import os
from shapely.geometry import Polygon

input = open(os.path.join("2025", "day_09", "input_day09.txt")).read().splitlines()

def part1(input):
    coords = [[int(y) for y in x.split(",")] for x in input]

    areas = []
    for xmin, ymin in coords:
        for xmax, ymax in coords:
            areas.append((abs(xmax - xmin) + 1) * (abs(ymax - ymin) + 1))

    largest_area = max(areas)

    return largest_area


print(part1(input))
4777967538
0.041 seconds elapsed

Part 2

import os
from shapely.geometry import Polygon

input = open(os.path.join("2025", "day_09", "input_day09.txt")).read().splitlines()

def part2(input):
    coords = [[int(y) for y in x.split(",")] for x in input]

    initial_area = Polygon(coords)

    areas = []
    for xmin, ymin in coords:
        for xmax, ymax in coords:
            rectangle = Polygon(
                [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
            )
            if initial_area.contains(rectangle):
                areas.append((abs(xmax - xmin) + 1) * (abs(ymax - ymin) + 1))

    largest_area = max(areas)

    return largest_area


print(part2(input))
1439894345
5.019 seconds elapsed

Day 10

Day 11

Day 12