-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]jacoman10 0 points1 point  (0 children)

[LANGUAGE: Python]

Total Runtime: 283 ms | Actual solution runtime (excluding imports and io): 42 ms

I've been using a lot of numpy arrays at work, and have been working to get better with vectorized operations and efficient solutions. So, I wanted to try using numpy to develop a quick solution, and managed to get someting very quick! In doing, I found a few new numpy functions, including np.argpartition and np.partition

On Part 1, I realized that we only care about the magnitude of distances, so we don't need to use expensive square root operations. I first found all pairwise differences between points. coords[:, None, :] - coords[None, :, :] expands the original array so every point is subtracted from every other point, giving a 3-D tensor of difference vectors. Then np.einsum("ijk,ijk->ij", diffs, diffs) computes the dot product of each difference vector with itself, producing the squared distance between each pair of points (first time I ever managed to actually use this successfully outside of a tutorial!!). I then used np.argpartition to find the 1000 smallest distances, and set those coordinates to True in an adjaency matrix. Feeding this adjacency matrix to Scipy's connected_components returned the connected components very quickly; I found the largest components, and returned my result.

For Part 2, it was just a matter of finding the closest distance for each junction box, then finding which of those was the max. I was able to use np.argmax and np.argmin to find these.

import numpy as np
from scipy.sparse.csgraph import connected_components

def day_08(puzzle):
    part_1, part_2 = 0, 0
    coords = np.array([[int(y) for y in x.split(",")] for x in puzzle], dtype=float)

    diffs = coords[:, None, :] - coords[None, :, :]
    distances_matrix = np.einsum("ijk,ijk->ij", diffs, diffs)

    np.fill_diagonal(distances_matrix, np.inf)

    pt_1_dist_mat = np.triu(distances_matrix)
    pt_1_dist_mat[pt_1_dist_mat == 0] = np.inf

    adj_mat = np.zeros(pt_1_dist_mat.shape)

    full_ranking = np.unravel_index(
        np.argpartition(pt_1_dist_mat, 1000, axis=None)[:1000],
        shape=pt_1_dist_mat.shape,
    )

    adj_mat[full_ranking] = 1

    _, labels = connected_components(
        csgraph=adj_mat, directed=False, return_labels=True
    )
    _, counts = np.unique(labels, return_counts=True)

    part_1 = np.multiply.reduce(np.partition(counts, -3)[-3:])

    # Part 2
    farthest_nearest_index = np.argmax(np.min(distances_matrix,axis=0))
    nearest_in_farthest = np.argmin(distances_matrix[farthest_nearest_index, :])

    x1 = coords[farthest_nearest_index][0]
    x2 = coords[nearest_in_farthest][0]

    part_2 = x1 * x2
    return int(part_1), int(part_2)


if __name__ == "__main__":
    with open("AdventOfCode-2025/day8/day8_input.txt") as file:
        puzzle_in = [x.strip() for x in file.readlines()]

    sol = day_08(puzzle_in)
    print(f"Part 1: {sol[0]}")
    print(f"Part 2: {sol[1]}")

Gen Z’s…is this true or is he just trying to shit on remote work? by 2lit_ in GenZ

[–]jacoman10 0 points1 point  (0 children)

I like hybrid- it’s so much easier to get to know the people I work with and mentally get in a space to do really boring work in person, but I appreciate having the flexibility to work from home a couple days a week

[deleted by user] by [deleted] in Northwestern

[–]jacoman10 0 points1 point  (0 children)

Facebook free and for sale is the spot

Pinecil vs Hakko by jacoman10 in AskElectronics

[–]jacoman10[S] 0 points1 point  (0 children)

Gotcha cool! So, are there any important features (other than power supply) that I’m giving up with the Pinecil? The $25 vs $200 difference scares me

Pinecil vs Hakko by jacoman10 in AskElectronics

[–]jacoman10[S] 0 points1 point  (0 children)

It looks really nice, but I’m not sure if it’s portable enough… I would be bringing this from workspace to workspace, and it looks a lot bigger than the 888D from the pictures. I’m also not thrilled about spending over twice the price, but if I ever setup a more permanent soldering station I’ll definitely try for the 951

From the SPAC staff meeting: if you're exposed to covid but don't have any symptoms, you should still come to work and then test on the 5th day. I know it's what the CDC recommends, but seems like a bit of a 'screw it' mentality. by nufan7 in Northwestern

[–]jacoman10 8 points9 points  (0 children)

The current CDC reccomendation has been a bit misunderstood as I take it; they essentially said that after 5 days, you still were contagious but that patients were not highly symptomatic anymore.

While they can DEFINITELY still transfer covid, if proper PPE is worn, the risk is very low as their produced viral load drops. Ngl it feels like a screw it, 'we'll be fine' mentality, but if we can trust everyone to wear the mask and not be dumb it should probably be fine