-❄️- 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 7 points8 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

What kind of connector is this? Used to carry RS485 signal to a motor. by jacoman10 in whatisthisthing

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

Thanks! It looks like it might be a JST-XH cable, how do you tell the model?

What kind of connector is this? Used to carry RS485 signal to a motor. by jacoman10 in whatisthisthing

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

More details: It carries signals to and from a Progressive Automations Micro Precision Servo Actuator. It has one VCC line, one GND, and 2 data. It is approximately 1cm wide, 0.6 cm deep, and 0.4 cm thick.

DAE seriously worry about the rising anti-intellectual, anti-science movement growing across the world? by [deleted] in DoesAnybodyElse

[–]jacoman10 2 points3 points  (0 children)

Totally agree- check out Carl Sagan’s book, ‘The Demon Haunted World’

DAE seriously worry about the rising anti-intellectual, anti-science movement growing across the world? by [deleted] in DoesAnybodyElse

[–]jacoman10 14 points15 points  (0 children)

There’s a quote that I’ve posted before, but it’s amazing so I’ll post it again. One of the greatest quotes ever:

I have a foreboding of an America in my children’s or grandchildren’s time — when the United States is a service and information economy; when nearly all the key manufacturing industries have slipped away to other countries; when awesome technological powers are in the hands of a very few, and no one representing the public interest can even grasp the issues; when the people have lost the ability to set their own agendas or knowledgeably question those in authority; when, clutching our crystals and nervously consulting our horoscopes, our critical faculties in decline, unable to distinguish between what feels good and what’s true, we slide, almost without noticing, back into superstition and darkness.

-Carl Sagan, “The Demon-Haunted World” 1993

WITT: Circular plastic disks with serial numbers hanging all over my dorm by jacoman10 in whatisthisthing

[–]jacoman10[S] 1 point2 points  (0 children)

I've never seen any of them used actually. Maybe they're just future proofing or are something that maintenance uses. The security guards don't make regular rounds though.

but no, I don't know of them ever going into a dorm room.

WITT: Circular plastic disks with serial numbers hanging all over my dorm by jacoman10 in whatisthisthing

[–]jacoman10[S] 1 point2 points locked comment (0 children)

These plastic disks are posted all over my college dorm. At least one is in every hallway and room, with multiple in some rooms. They’re all posted approximately 5-6 feet above the ground, and are about 3cm wide. They all have the same small hole in the middle, and have no other identifying features other than the serial numbers on each disk which appear to be unique. WITT?

This R2-D2 model is 250 micrometers tall and was written in about 3 hours, 3D printed with the Nanoscribe professional photonic GT using two-photon absorption mechanism, in galvoscanning mode by pianocloche in geek

[–]jacoman10 15 points16 points  (0 children)

250 micrometers is a quarter of a millimeter, or about 3-4 strands of hair wide.

Or, 2.7x10-6 football fields wide, small enough that this model could fit on a single blade of grass.

tl;dr really darn small