#advent of code 2025

1 messages ยท Page 7 of 1

cloud iron
#

ok so d7p1 is easy

#

but what the fuck is that p2

lusty atlas
#

u got this

cloud iron
#

yeah i know

#

it's just classic exploration

#

and we can do breadth first or depth first, doesn't even matter

#

annoying algo to write tho

frigid socket
#

oh wait @lusty atlas i got an IDEA

#

||as soon as i reach the final splitter i blacklist its left side and when i reiterate it itโ€™s forced to use the right side and then blacklist the left side of the parent splitter and all||

cloud iron
#

did you guys wrote breadth first or depth first ?

#

i want to innovate

frigid socket
#

what is breadth

#

bread th

cloud iron
#

when you check line per line

#

looking not at the depth but at the width

cloud iron
pale stirrup
#

new output

cloud iron
#

actually if i do DFS and don't want time to explode i have to like memoize and shit

#

and do recursive stuff

#

and i hate that

#

so time for dynamic BFS programming

pale stirrup
robust yacht
#

yop

pale stirrup
#

you also love my shell prompt

robust yacht
#

maybe

pale stirrup
#

looks worse there bc no ide has a good looking terminal

lusty atlas
pale stirrup
#

nopp

#

i made most of that last year

#

i just added stuff for expected results

cloud iron
#

did someone do DFS with the whole recursive and memoization stuff ?

cloud girderBOT
# pale stirrup ||https://github.com/wingio/advent-of-code/blob/2025/aoc%2Fsolver%2Fsrc%2Fcommon...

aoc/solver/src/commonMain/kotlin/solver/solutions/Day07.kt: Lines 16-28
||```kt
part2(expected = 40941112789504) {
val manifold = Grid.charGrid(input)
val cache = mutableMapOf<Point, Long>()

fun search(point: Point): Long = cache.getOrPut(point) {
    when(manifold.getOrNull(point.down)) {
        '^' -> search(point.left) + search(point.right)
        '.' -> search(point.down)
        else -> 1
    }
}
search(manifold.pointOfFirst { it == 'S' })

}

cloud iron
#

i'm pretty sure that BFS is faster than DFS cause BFS is O(row*col) and DFS is O(solution) (at max but can go lower thanks to memoization)

cloud iron
#

isn't it ?

#

yeah it is

pale stirrup
#

idk maybe

cloud iron
#

i mean no actually

pale stirrup
#

i didn't map out how it searched

cloud iron
#

you're doing DFS

#

recursion makes me always confused

#

iteration is a fancy form of recursion

frigid socket
#

might ask ai for d7p2

cloud iron
#

no

pale stirrup
#

don't

cloud iron
#

don't give up

frigid socket
#

jkjk i dont use AI you know you know

cloud iron
#

you have 2 both valid choices

pale stirrup
#

look at our solutions before if you're really that stuck

frigid socket
#

i have a plan

cloud iron
#

BFS like me and dynamic programming
or DFS like wingd with recursion and memoization

pale stirrup
#

both are actually fast if you aren't stupid

feral valve
#

this is dfs

cloud iron
#

mmmm

#

doesn't seem that bad

#

i hate recursion

#

but to be trained, i'll do it

feral valve
#

recursion is super clean here

lusty atlas
#

i used DFS

cloud iron
#

yeah but look at my BFS

#

it's so nice

lusty atlas
#

with recursion too

cloud iron
#

dynamic programming so cool

#

also i think faster

pale stirrup
#

that seems to just be the easier solution

cloud iron
#

it's why i'll code both actually

#

i wanna see which is better

lusty atlas
#

have u tried crystal

pale stirrup
#

yeah I've done meth

feral valve
lusty atlas
#

try it!!

#

crystal is just compiled + typed ruby

feral valve
#

i think iโ€™ve heard you praise it previously

lusty atlas
#

ruby is so fucking slow

feral valve
#

oh wow crystal has macros

#

thatโ€™s pretty cool

lusty atlas
#

yesss

feral valve
#

mmm crystal looks pretty good

#

i like the typing at a glance as well

lusty atlas
#

the typing is very out of your way and mostly inferred, you hardly ever have to specify types

#

only when creating empty hash, array etc

feral valve
#

def add(a, b)
a + b
end

add 1, 2 # => 3
add "foo", "bar" # => "foobar"

i liked this example

#

i canโ€™t think of what itโ€™d actually be used for though, other than stuff like print

cloud iron
#

note don't try to use a tuple as a key for a map in javascript

lusty atlas
#

biggest dsa nerd

cloud iron
#

it doesn't go well

lusty atlas
#

just stringify it or smth xD

#

x_y

feral valve
#

hmm crystals pattern matching looks lackluster

cloud iron
#

yeah so there's kinda no contest here
i didn't forget to do warmup iterations btw

cloud iron
lusty atlas
feral valve
#

i donโ€™t know ruby

#

but i doubt it matches rust or ocaml, of which i really enjoy using

lusty atlas
#

make ur own pattern matching macro

cloud iron
#

ok so actually my BFS was only slower cause of my key being a string, but they are actually the same

cloud iron
pale stirrup
#

what does dp stand for

robust yacht
#

DISTANCE

#

i already hate this

#

ok i literally do not undersatnd this what the fuck

dusky frost
terse edge
#

@native maple n part 1 what happens if i get boxes a and b where a is already present in one circuit and b is present in another?
do i merge the circuits?

#

oh ur asleep

pale stirrup
#

i can successfully get the distance between any two coordinates (||using euclidean||) just don't know how to sort them

#

do i need to get every possible pair?

robust yacht
#

||i dont think sort is necessary. i think you have to find the closest junctions on each iteration||

pale stirrup
#

||so just iterate through the list and find the closest to each item?||

robust yacht
#

||thats what im trying||

#

im able to get the first closest pair

#

wait

#

im close

#

nvm

fallen lily
robust yacht
#

@pale stirrup have you figured ito ut

pale stirrup
#

i feel like im close

robust yacht
#

io cant figure out the condition i need to skip

verbal parrot
#

has nun of u done it yet is it that hard

#

i havenโ€™t rly read the problem i just read โ€œx, y, zโ€ and closed the tab

robust yacht
#

my ide is compeltly broken wtf

#

never had this happen

robust yacht
#

@pale stirrup idk what to do help

verbal parrot
#

are u supposed to like find the shortest pair of boxes every iteration?

#

how do u do it efficently fr

robust yacht
#

ok apparently there's a data structure that works for this: ||disjoint set union||

terse edge
#

@native maple

#

stupid Day

#

like

#

the problem isnt described in the puzzle description

robust yacht
#

yop

#

bad

terse edge
#

@native maple and whoever else didnt do it yet, im not spoilering it because its not described in the puzzle description but an integral part of what youre supposed to do

see c and d, connect them
see a and c, add to [c, d]
see b and d, add to [c, d, a]
see a and b, do nothing, still increment the counter
see a and b, do nothing, dont increment the counter
pale stirrup
#

what counter

#

is that p2

robust yacht
#

@pale stirrup hi

pale stirrup
#

im very confused

robust yacht
#

guh i dont know how to apply ||DSU|| to this

#

i hate mathematical problems

#

wtf some of hte solutions are so much simpler

pale stirrup
#

my solution so far generated circuits with 3 items

robust yacht
#

are you still doing it

pale stirrup
#

probably gonna save it for later

#

its 2am and i don't think I've made much progress

robust yacht
#

me too

pale stirrup
#

@terse edge can you send me all the circuits for the example input so that i can debug my solution

terse edge
# pale stirrup <@415132870252822539> can you send me all the circuits for the example input so ...
16.902: [162, 817, 812] - [425, 690, 689]
321.560: [162, 817, 812] - [431, 825, 988]
322.369: [906, 360, 560] - [805, 96, 715]
328.119: [431, 825, 988] - [425, 690, 689]
333.656: [862, 61, 35] - [984, 92, 344]
338.339: [52, 470, 668] - [117, 168, 530]
344.389: [819, 987, 18] - [941, 993, 340]
347.599: [906, 360, 560] - [739, 650, 466]
350.786: [346, 949, 466] - [425, 690, 689]
352.936: [906, 360, 560] - [984, 92, 344]
robust yacht
#

whar

#

thats just distances?

fallen lily
#

Guh how bad is d8

terse edge
#

note how 431 y z and 425 y z appear twice each

pale stirrup
#

top is supposed to be 316 right

#

i think you cut off the 3

terse edge
#

ye

native maple
#

just woke up

#

i'll do it in the car

robust yacht
#

@native maple hii

#

i spent 2h ours and havent made any progress

#

roie will solve in < 10 minutes

native maple
#

is this the prophesized ramp up in difficulty

terse edge
#

the description is retarded

#

its not that hard

#

its just hard to understand

#

if you guess right at the start yuo win

pale stirrup
#

i have this so im definitely doing something wrong

terse edge
#

we had ppl do it in 3 mins and i have this

robust yacht
terse edge
#

@native maple

robust yacht
#

@pale stirrup sleep

#

you can't get it before me

terse edge
#

@robust yacht

robust yacht
#

@terse edge

terse edge
#

@robust yacht @pale stirrup @native maple doing nothing counts as connecting two cables if you havent seen that exact pair of cables before (even if theyve appeared before and you added them to circuits)

pale stirrup
terse edge
#

then compare

robust yacht
#

what would I even store my connections as

terse edge
#

why do you have more than 10 connections

terse edge
robust yacht
#

HashMap<Vec3, List<Vev3>>

#

how

pale stirrup
#

my second step generates a list of circuits

terse edge
#

i store a MutableList<HashSet<Point3D>>

robust yacht
#

I'm stuck with knowing what points to skip

pale stirrup
#

yeah im gonna pause for now

native maple
#

hold on lol

robust yacht
terse edge
#

not 10

#

even tho it says 10

robust yacht
#

oh

terse edge
#

ur supposed to count doing nothing as making connections

robust yacht
#

guh

#

then my logic won't even work

terse edge
#

nothing happens BESIDES your counter getting incremented

robust yacht
#

I make connections then calculate seperate

robust yacht
#

how do you determine when to skip

pale stirrup
#

if both a and b are already in any other circuits, i skip?

robust yacht
#

if I do skip when ciruits.any { a in it || b in it} I get stuck in loop

#

it keeps finding the same closest points

#

eagely teach me your wisdom

terse edge
terse edge
#

because yuo connected a and b

pale stirrup
#

hm

#

definitely something to sleep on

robust yacht
#

I was getting like 20 circuits

#

with the example

terse edge
#

you cant use hashset<circuit>, if you remove circuit to merge it hashset wont remove it sometimes idk why

#

use mutablelist<circuit>

#

i wasted an hour on that

pale stirrup
#

my issue is im getting too few circuits

#

only 6

robust yacht
#

oh yea

#

I got 6 too

terse edge
#

print the circuits at the end

pale stirrup
#

i do

terse edge
#

give me

#

the output

pale stirrup
terse edge
pale stirrup
#

im not running a fixed amount of times

terse edge
#
(40, [862-61-35, 739-650-466, 984-92-344, 805-96-715, 906-360-560]
[346-949-466, 431-825-988, 425-690-689, 162-817-812]
[117-168-530, 52-470-668]
[941-993-340, 819-987-18]
[57-618-57]
[592-479-940]
[352-342-300]
[466-668-158]
[542-29-236]
[216-146-977]
[970-615-88])
terse edge
#

yuore supposed to run 10 times

robust yacht
#

mine just has a queue and finds the next closest circuit on each iteration

robust yacht
terse edge
#

for sample 10 times

#

for real input 1000

#

first line of each paragraph

robust yacht
#

guh

#

could've been more obvious

terse edge
robust yacht
#

guhhh so short

#

my p1 alone is already nearly 50 lines

terse edge
hoary mirage
#

NOT A BUG

native maple
#

ok well i did it

#

but i don't like my solution much

terse edge
#

@native maple i prefer 6am over 10am

#

2nd day in a row that someone wanted to do smth at 10am

#

yday my aunt came over while i was doing aoc

#

today i was gonna go to the barber at 10 if it wasnt for aoc

brazen salmon
#

@frigid socket

frigid socket
#

fake samara

#

i'll try doing AI of Code d7p2

frigid socket
#

@native maple i found issue with my 7p2

#

no AI needed to fix

#

That's the right answer! You are one gold star closer to decorating the North Pole.

You have completed Day 7! You can [Share] this victory or [Return to Your Advent Calendar].

#

@pale stirrup is my only way out of d8 to bruteforce

#

might be tbh

pale stirrup
#

idk i haven't solved yet

frigid socket
#

i would do typescript (not types the language) but i have a no JS/TS rule

verbal parrot
#

why does go not have tuples

frigid socket
#

@lusty atlas is there good crystal lsp

native maple
#

WHY IS MY SOLUTION SO SLOW

#

takes 1.5s

verbal parrot
#

go so hard

#

legit as hard as c++

frigid socket
#

ig ill have to do without lsp

verbal parrot
#

who thought it was a good idea to make slice.append(el) a global function append(slice, el)

frigid socket
#

me

verbal parrot
#

thats why rust is better ๐Ÿ˜…

frigid socket
#

might ban @verbal parrot soon ykyk

#

at least you have a lsp @verbal parrot

#

and i do not

verbal parrot
#

it kinda works
faint@faints-MacBook-Pro 08 % go run 08.go
[{{162 817 812} {425 690 689}} {{162 817 812} {431 825 988}}

#

i got the first shortest paths correctly

#

if only i didnt start solving it six hours after it started

verbal parrot
#

i didnt have one when i was doing it in elixir

#

cuz the lsp expected me to have an elixir project and i was just doing it single file fr

frigid socket
#

yeah same for crystal

#

i think

#

vee will know more

#

im so good @verbal parrot

verbal parrot
#

do d8

frigid socket
#

im doing

#

d8 seems cancer

#

@verbal parrot i can now list tuples

#

revolutionary

verbal parrot
#

ykyk just fmt.Println(slice) ykyk

#

@terse edge what is the example supposed to output?

#

this so dumb like why do they only show output for first 10 shortest ones

#

if the example is fucking 20 boxes

#

holy fuck my shit so fast

Benchmark 1: go run 08.go
  Time (mean ยฑ ฯƒ):     15.441 s ยฑ  7.807 s    [User: 15.152 s, System: 0.168 s]
  Range (min โ€ฆ max):    0.294 s โ€ฆ 19.522 s    10 runs```
#

@frigid socket holy sh*t man it works with the example

40```
#

but it doesnt with the actual input ๐Ÿ˜ญiPray

frigid socket
#

that's my life

#

d1p2 does that

verbal parrot
#

guh idek what cud be wrong

frigid socket
#

@verbal parrot

#

fainting my faint

verbal parrot
#

๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘

#

oh wait im dumb it says i need to combine 1000 pairs

#

pairs

native maple
#

@terse edge how long does yours take

frigid socket
#

i have 1000 boxes

verbal parrot
#

1000 boxes โ‰  1000 pairs

hoary mirage
#

@native maple what is day 8

#

explain

frigid socket
#

you cannot make 1000 pairs from 1000 boxes

verbal parrot
#

yes you can?

hoary mirage
#

vai Equipped with a new understanding of teleporter maintenance, you confidently step onto the repaired teleporter pad.

You rematerialize on an unfamiliar teleporter pad and find yourself in a vast underground space which contains a giant playground!

Across the playground, a group of Elves are working on setting up an ambitious Christmas decoration project. Through careful rigging, they have suspended a large number of small electrical junction boxes.

Their plan is to connect the junction boxes with long strings of lights. Most of the junction boxes don't provide electricity; however, when two junction boxes are connected by a string of lights, electricity can pass between those two junction boxes.

The Elves are trying to figure out which junction boxes to connect so that electricity can reach every junction box. They even have a list of all of the junction boxes' positions in 3D space (your puzzle input).

For example:

162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689
This list describes the position of 20 junction boxes, one per line. Each position is given as X,Y,Z coordinates. So, the first junction box in the list is at X=162, Y=817, Z=812.

To save on string lights, the Elves would like to focus on connecting pairs of junction boxes that are as close together as possible according to straight-line distance. In this example, the two junction boxes which are closest together are 162,817,812 and 425,690,689.

By connecting these two junction boxes together, because electricity can flow between them, they become part of the same circuit. After connecting them, there is a single circuit which contains two junction boxes, and the remaining 18 junction boxes remain in their own individual circuits.

Now, the two junction boxes which are closest together but aren't already directly connected are 162,817,812 and 431,825,988. After connecting them, since 162,817,812 is already connected to another junction box, there is now a single circuit which contains three junction boxes and an additional 17 circuits which contain one junction box each.

The next two junction boxes to connect are 906,360,560 and 805,96,715. After connecting them, there is a circuit containing 3 junction boxes, a circuit containing 2 junction boxes, and 15 circuits which contain one junction box each.

The next two junction boxes are 431,825,988 and 425,690,689. Because these two junction boxes were already in the same circuit, nothing happens!

This process continues for a while, and the Elves are concerned that they don't have enough extension cables for all these circuits. They would like to know how big the circuits will be.

After making the ten shortest connections, there are 11 circuits: one circuit which contains 5 junction boxes, one circuit which contains 4 junction boxes, two circuits which contain 2 junction boxes each, and seven circuits which each contain a single junction box. Multiplying together the sizes of the three largest circuits (5, 4, and one of the circuits of size 2) produces 40.

Your list contains many junction boxes; connect together the 1000 pairs of junction boxes which are closest together. Afterward, what do you get if you multiply together the sizes of the three largest circuits?

explain shortly cant bother to read

spring lionBOT
# hoary mirage vai Equipped with a new understanding of teleporter maintenance, you confidently...

The problem describes connecting junction boxes in 3D space to form electrical circuits.

Here's the gist:

  1. You're given 3D coordinates for many junction boxes.
  2. Calculate the straight-line distance between every possible pair of junction boxes.
  3. Connect the 1000 pairs that are closest together. When two boxes are connected, they become part of the same circuit. If boxes already in the same circuit are connected, it doesn't change anything.
  4. After making these 1000 connections, identify all the distinct circuits that have formed.
  5. Find the sizes of the three largest circuits and multiply those three sizes together.

-# Response generated by gemini-2.5-flash. AI may be incorrect or misleading.

verbal parrot
#

NO

#

DELETE

#

NO SPOILERS

hoary mirage
#

THIS IS NOT SPOILER

frigid socket
#

faint are you dumb

#

this is puzzle text

verbal parrot
#

oh

quartz aurora
#

Okay I managed to get this down to 348 bytes (with a big ugly blob of extra garbage output): ||```py
S=[]
Z=sorted
for L in open(n:=0):S+=[map(int,L.split(',')),len(S)],
T=1000
D,=V=[-1]T
R=lambda v:R(V[v])if-1<V[v]else v
for _,i,j in Z((sum((a-b)**2 for a,b in zip(I,J)),i,j)for
I,i in S for
J,j in S[:i]):
if n==T:
_,p,q,r=Z(dv for d,v in zip(D,V));k=pq*r
A,B=R(i),R(j);n+=1
if A!=B:V[A]=B;D[B]+=D[A]
if-T==D[B]:-print(k,S[i][0]*S[j][0])

frigid socket
#

you have lost it

verbal parrot
#

@frigid socket idk if u were being serious about "u cant make 1000 pairs from 1000 boxes" but imagine u have 4 boxes [a,b,c,d]. these are the pairs u can make with them: [(a,b), (a,c), (a,d), (b,c), (c,d)]

frigid socket
#

oh icic

#

so instead of calculating the 10 closest you calculate the 1k closest?

verbal parrot
#

for puzzle input yes

hoary mirage
#

WHY ASK THAT

verbal parrot
#

The next two junction boxes are 431,825,988 and 425,690,689. Because these two junction boxes were already in the same circuit, nothing happens!
somehow without this condition my example output is correct but without it it's incorrect

frigid socket
#

@hoary mirage furrykafasi

hoary mirage
#

die

quartz aurora
quartz aurora
native maple
#

WHY IS IT SO HARD TO MAKE A FAST ONE TODAY

#

mine runs in 1.5s

verbal parrot
frigid socket
#

HOW doe sthat even work

#

im gonna kill myself

quartz aurora
verbal parrot
#

how do u check if there's no public leaderboard anymore fr

native maple
#

probably top rankers for solution speed not solve speed

verbal parrot
#

yeah but still how do u see this without global leaderboard

native maple
quartz aurora
verbal parrot
#

oh thought so

quartz aurora
#

So there's no way to know the actual global fastest

frigid socket
#

@verbal parrot so
||

- find the closest ranking boxes
- put them in the same circuit
- find the closest ranking boxes that aren't in an identical circuit
- do that 1000 times

||

#

is this sane

native maple
#

i would use a disjoint set union whatever but that doesnt exist in elle

hoary mirage
#

rosieeeeee

native maple
#

i dont have scipy or nx or whatever

frigid socket
#

faint ghosting me

native maple
#

wait

#

would it be faster to use a min heap than to sort by distance

native maple
#

wait wrong day

urban ginkgoBOT
#

Alright @frigid socket, in 9 hours, 30 minutes and 30 seconds: โ€ฆ

verbal parrot
#

i guess "counter" is supposed to be for p2 though

quartz aurora
#

The HashSet::from(circuits).size() part looks pretty slow

verbal parrot
#

also looking at eagely's delta time i assume p2 is like really easy? can someone confirm

quartz aurora
#

Some people also ||spatially partition the inputs so they don't need to generate all the pairs||

native maple
#

the slowest part is the computation of the dists array

quartz aurora
#

Yeah

frigid socket
#

how do you see delta time @verbal parrot

native maple
verbal parrot
#

i think its an extensin

#

yeah

native maple
#

actually

#

i think i know how to make this faster

#

i did this in a very fucked up way

#

position_with is O(n)

#

i can just do a double for loop with .enumerate instead of using T[].combinations

#

and use the indexes from there directly isntead of computing them every time

verbal parrot
#
if index1 != -1 && index2 != -1 {
  fmt.Println(pair)
  continue
}
faint@faints-MacBook-Pro 08 % go run 08.go
{{431 825 988} {425 690 689}}
{{906 360 560} {984 92 344}}
24
if index1 != -1 && index2 != -1 {
  // continue
}```

faint@faints-MacBook-Pro 08 % go run 08.go
30

whyyy ๐Ÿ˜ญ
#

OH WAIT

#

it says "in the same circuit"

#

omfg

native maple
#

ok thats better

verbal parrot
#

nvm it still doesnt work

#

fucking hell

quartz aurora
#

||And assume that there's enough points in those to fulfill both tasks' conditions, so that the missing pairs don't matter||

native maple
#

oh hmmm

#

interesting

hoary mirage
#

how is there single circuits if all of them connect to shortest one to them

verbal parrot
hoary mirage
native maple
#

you do better then

#

lmao

hoary mirage
#

@native maple according to my calculations my solution will take 1 hour 33 minutes

#

ig I can sort

#

sorting is always good option

frigid socket
#

mantikafasi mental illness

quartz aurora
#

A friend advised me that map(int,L.split(',')) can be more succinctly written as ||eval(L)||, which is extremely based

terse edge
terse edge
#

also make sure ur handling the case where both cables exist in the same box

#

u should count the first time u see them but not the second time

#

the first time you see that exact pair counts

#

if a cable has appeared before but in a different pair it doesnt count

native maple
pale stirrup
#

i love a well formatted and documented function

/**
 * Calculates the straight-line distance between this and another [point]
 * in 3-dimensional space, see [euclideanDistance] for 2D points
 *
 * https://en.wikipedia.org/wiki/Euclidean_distance
 */
fun Point3D.distanceTo(point: Point3D): Double {
    return sqrt(
        /* x */ (point.x.toDouble() - x.toDouble()).pow(2) +
        /* y */ (point.y.toDouble() - y.toDouble()).pow(2) +
        /* z */ (point.z.toDouble() - z.toDouble()).pow(2)
    )
}
native maple
#

why do you need all of that for a euclidean distance ๐Ÿ˜ญ

pale stirrup
#

?

hoary mirage
#

my solution still hasnt finished

#

love

#

python so slow

frigid socket
#

WHY ARE YOU USฤฐNG PYTHON

#

C++

#

or crystal

#

or Vlang

hoary mirage
#

nin0 is caveman

frigid socket
#

vlang is high level yk

hoary mirage
#

ugly

#

and hgorrible langauge server

frigid socket
#

It has worked well for me

#

with my solution

cloud girderBOT
native maple
#

rate

#

you don't even need the whole distance it's enough to use the distance squared

pale stirrup
#

i have it extracted to a util so it needs to work for more than just this one puzzle

#

maze tomorrow ๐Ÿคž

verbal parrot
# terse edge also make sure ur handling the case where both cables exist in the same box

these are all the cases im handling isnt it enough
||```go
if len(circuits) == 0 {
circuits = append(circuits, make([]Vec3, 2))
circuits[0][0] = pair.a
circuits[0][1] = pair.b
continue
}

    index1 := find(&circuits, pair.a)
    index2 := find(&circuits, pair.b)

    if index1 == -1 && index2 == -1 {
        circuits = append(circuits, make([]Vec3, 2))
        circuits[len(circuits)-1][0] = pair.a
        circuits[len(circuits)-1][1] = pair.b
        continue
    }

    if index1 == index2 {
        continue
    }

    if index1 != -1 {
        circuits[index1] = append(circuits[index1], pair.b)
    } else if index2 != -1 {
        circuits[index2] = append(circuits[index2], pair.a)
    }
#

smart peopll #HELP

pale stirrup
#

asking the wrong server ykyk

verbal parrot
#

erm

verbal parrot
pale stirrup
#

a, b and b, a

verbal parrot
#

dont increment the counter = dont count the current pair to these 10 pairs?

#

or well 1000 for the real input

pale stirrup
#

honestly idk what counter eagely was talking about

verbal parrot
#

why does it not work ๐Ÿ˜ญ
||```go
type Vec3 struct {
x, y, z int
}

type Pair struct {
a, b Vec3
}

func (v1 Vec3) distance(v2 Vec3) int {
sum := (v1.x-v2.x)(v1.x-v2.x) + (v1.y-v2.y)(v1.y-v2.y) + (v1.z-v2.z)*(v1.z-v2.z)
return int(math.Abs(math.Sqrt(float64(sum))))
}

func pairs(fileName string) []Pair {
var vecs []Vec3
var pairs []Pair

file, _ := os.Open(fileName)
defer file.Close()

scanner := bufio.NewScanner(file)

for scanner.Scan() {
    xyz := strings.Split(scanner.Text(), ",")
    x, _ := strconv.Atoi(xyz[0])
    y, _ := strconv.Atoi(xyz[1])
    z, _ := strconv.Atoi(xyz[2])

    vecs = append(vecs, Vec3{x, y, z})
}

for index, vec := range vecs {
    for j := index + 1; j < len(vecs); j++ {
        pairs = append(pairs, Pair{vec, vecs[j]})
    }
}

return pairs

}

func sort_pairs(pairs []Pair) {
sort.Slice(pairs, func(i, j int) bool {
return pairs[i].a.distance(pairs[i].b) < pairs[j].a.distance(pairs[j].b)
})
}

type Circuits struct {
dict map[int]int
}

func find(circuits *[][]Vec3, vec Vec3) int {
for i, circuit := range *circuits {
if slices.Contains(circuit, vec) {
return i
}
}
return -1
}

func puzzle(pairs *[]Pair) int {
var circuits [][]Vec3
for i, pair := range *pairs {
if i > 9 {
break
}

    if len(circuits) == 0 {
        circuits = append(circuits, make([]Vec3, 2))
        circuits[0][0] = pair.a
        circuits[0][1] = pair.b
        continue
    }

    index1 := find(&circuits, pair.a)
    index2 := find(&circuits, pair.b)

    if index1 == -1 && index2 == -1 {
        circuits = append(circuits, make([]Vec3, 2))
        circuits[len(circuits)-1][0] = pair.a
        circuits[len(circuits)-1][1] = pair.b
        continue
    }

    if index1 == index2 {
        continue
    }

    if index1 != -1 {
        circuits[index1] = append(circuits[index1], pair.b)
    } else if index2 != -1 {
        circuits[index2] = append(circuits[index2], pair.a)
    }
}

sort.Slice(circuits, func(i, j int) bool {
    return len(circuits[i]) > len(circuits[j])
})

return len(circuits[0]) * len(circuits[1]) * len(circuits[2])

}

func main() {
pairs := pairs("input")
sort_pairs(pairs)
fmt.Println(puzzle(&pairs))
}

pale stirrup
#

i don't have a counter

verbal parrot
#

this is what it looks like for me for example input (first line is the current pair, next line is lengths of circuits X times)

{{162 817 812} {425 690 689}}
2
{{162 817 812} {431 825 988}}
3
{{906 360 560} {805 96 715}}
3 2
{{431 825 988} {425 690 689}}
3 2
{{862 61 35} {984 92 344}}
3 2 2
{{52 470 668} {117 168 530}}
3 2 2 2
{{819 987 18} {941 993 340}}
3 2 2 2 2
{{906 360 560} {739 650 466}}
3 3 2 2 2
{{346 949 466} {425 690 689}}
4 3 2 2 2
{{906 360 560} {984 92 344}}
4 4 2 2 2
{{592 479 940} {425 690 689}}
4 4 2 2 2```
#

which kinda... makes sense to me?

#

but it seems to be wrong

#

but if i remove the if index1 == index2 { continue } it works

#

fucking how

terse edge
#

or just take only the first thousand pairs and loop over them

pale stirrup
verbal parrot
#

oh my fucking god finally

That's the right answer! You are one gold star closer to decorating the North Pole. [Continue to Part Two]

robust yacht
#

@pale stirrup

#

you weren't supposed to get it until after I got it

verbal parrot
#

this was the case i didnt handle right (or didnt handle entirely):
||go if index1 != -1 && index2 != -1 { circuits[index1] = append(circuits[index1], circuits[index2]...) circuits[index2] = make([]Vec3, 0) continue }||

robust yacht
#

wing cheating

pale stirrup
#

i did just copy one of eagely's utils actually (credited though)

robust yacht
#

guh

verbal parrot
#

p2 done!!!

That's the right answer! You are one gold star closer to decorating the North Pole.

You have completed Day 8! You can [Share] this victory or [Return to Your Advent Calendar].

native maple
#

THATS MORE LIKE IT

verbal parrot
#

also i now get what eagely meant by counter

feral valve
#

i should look up how to do closest pair efficiently

robust yacht
verbal parrot
#
faint@faints-MacBook-Pro 08 % hyperfine -N 'go run 08.go'
Benchmark 1: go run 08.go
  Time (mean ยฑ ฯƒ):     184.9 ms ยฑ  93.8 ms    [User: 155.0 ms, System: 73.2 ms]
  Range (min โ€ฆ max):   153.2 ms โ€ฆ 451.9 ms    10 runs

wait how did it get so fast my p1 only code was 15s fr

native maple
#

ok thats better

verbal parrot
#

my next lang is pascal fr

robust yacht
native maple
#

all solutions in 300ms

#

i will take that

hoary mirage
#

@native maple still hasnt calculated

#

waiting

#

it should finish soon

#

I could just make a array for smallest 1000 connections but too lazy

vestal owl
#

goddamit bubble sort

native maple
#

is that 350 seconds ๐Ÿ˜ญ

vestal owl
#

yes

lusty atlas
#

IS TODAY DIJKSTRA DAY

dusky frost
#

nah

native maple
robust yacht
#

never i hope

vestal owl
#

haha

hoary mirage
#

COME ON END ALREADY

#

I AM GOING INSANE

vestal owl
#

baka

hoary mirage
#

my algo is peak

native maple
hoary mirage
native maple
#

well i think its partly my stuff heap allocating

robust yacht
#

elle slow

#

@hoary mirage make elle fast

hoary mirage
#

impossible

vestal owl
#

p2 was way too easy

#

it's like 2 lines apart from p1

native maple
robust yacht
#

@native maple you didnt ask me you hate me

#

elle so bad

#

soooo broke

#

fixx

native maple
#

wtf

dusky frost
#

identifier too long

#

I remember that error

robust yacht
#

3.2k lines elle so bloated

#

rewrirte

vestal owl
#

both parts take this long

#

ugh

native maple
#

oh ok its not faster than mine

#

mine takes 100ms for both

native maple
vestal owl
robust yacht
native maple
#

single static assignment

robust yacht
#

idk what that is

vestal owl
#

compiler optimization

#

basically it keeps every mutation in a new variable (not quite but that's the basic idea)

robust yacht
#

o

#

@native maple how fix

vestal owl
#

anyways i should use stdlib's qsort more often

#

it's way too helpful

#

and takes a comparison function too

#

and __compar_fn_t takes in 2 void* params and outputs -1, 0 or +1

vestal owl
#

bro cant math ๐Ÿ˜ญ

robust yacht
#

well

#

roie does like lambda calculus for fun theyre insane

vestal owl
#

incredible

native maple
vestal owl
#

anyways -Ofast helps a bit too

native maple
vestal owl
robust yacht
#

oh

#

guhh ill have to compil qbe manually

vestal owl
robust yacht
#

i dont like installing system packages like this

native maple
cloud girderBOT
native maple
#

huh

#

guh

robust yacht
#

elle 2

#

roieee

native maple
robust yacht
#

nop

#

using pacman repos version

native maple
#

i forget some people just install qbe blindly

vestal owl
native maple
#

it's fine building it yourself is like dead easy if ur on linux

robust yacht
#

elle should maybe submodule qbe if qbe is gonna be broken like that

native maple
#

i will

robust yacht
#

qbe in elle when

native maple
#

because that way i can also add inline asm

vestal owl
#

i don't think i've ever used the qsort function until now

native maple
robust yacht
#

huskkk

#

qbe using long long

vestal owl
#

also can you try to run it on your computer too

#

with -Ofast -lm

native maple
#

sure hold on

robust yacht
#

i think i need your input

native maple
robust yacht
#

give your input i dont have mine solved yet

native maple
#

it takes the file from args[1] i didn't bother to add help message

robust yacht
#

@native maple@native maple make a aoc solution wrapper thing

#

mine are all contained as one program

#

inputs are stored in the resources

#

inputt @native maple give

robust yacht
#

SLOW

native maple
native maple
#

guh

robust yacht
native maple
#

do you have updated elle

robust yacht
#

yes

native maple
#

guh

robust yacht
#

it solves without --nogc

#

but slow

native maple
#

it should solve without gc too whatttt

#

do you know how to use gdb

robust yacht
#

yes

native maple
#

can you send bt

robust yacht
#

i will try

#

how compile with debug symbols @native maple

native maple
#

you just need to gdb ./solution then r input.txt then when it crashes bt and send

native maple
robust yacht
#

oh okay

#

good luck interpreting this

#0  0x00007ffff7da82e4 in ?? () from /usr/lib/libc.so.6
#1  0x000055555555f945 in ArenaAllocator.realloc ()
#2  0x0000555555564b3a in ArbitraryAllocator.realloc ()
#3  0x000055555555977b in Array.resize.0.Triple.0.13.7.7.1.1 ()
#4  0x000055555555c607 in Array.push.0.Triple.0.13.7.7.1.1 ()
#5  0x00005555555560c0 in MinHeap.push.0.Triple.0.13.7.7.1.1 ()
#6  0x000055555555582f in solve ()
#7  0x000055555555b388 in __internal.elle.__main__ ()
#8  0x000055555555741c in main ()

native maple
#

no that's helpful

#

thank you

robust yacht
#

how

#

okay

native maple
#

because that means it's fucking up when reallocating an arena region to be bigger, maybe you OOM

robust yacht
#

how

#

i have 64 gb

native maple
#

try add use std/heap_allocator; at the top and then #set_allocator(HeapAllocator::new()); at the start of main() and see if it works

#

i can probably reproduce on my machine hold on

lusty atlas
#

not anymore

robust yacht
#

use std/heap_allocator;

lusty atlas
#

zt doesn't realise he got scammed and his ram is really only 8gb but manipulated to report itself as 64gb

robust yacht
native maple
#

oh

native maple
#

guh look at the error above

#

use std/allocators/heap_allocator;

robust yacht
#

use std/allocators/heap_allocator;

#

@native maple

lusty atlas
#

rosie doesn't know her own language

robust yacht
#

roie fail

native maple
#

oh im restarted

#

use std/allocators/heap;

#

in my defense i never use this allocator

#

and im on mobile

lusty atlas
#

rosie is asking ai how to fix this error @robust yacht

robust yacht
#

yop

#

rosie has a prompt trained on elle

lusty atlas
robust yacht
#

@native maple

spring lionBOT
# lusty atlas vai how to fix this error please?

The error you're encountering has two main parts:

  1. "Could not load module std/allocators/heap_allocator: No such file or directory (os error 2)"
    This indicates that the compiler or runtime cannot find the heap_allocator module, likely because it's missing, misplaced, or the path to it is incorrect. This is similar to a "ModuleNotFoundError" in other languages.

  2. "Identifier 'HeapAllocator' isn't a struct or primitive type."
    This means the HeapAllocator type is not recognized in the scope where it's being used. This could be due to:

    • Incorrect spelling (though the error asks if you spelled it correctly, it's worth double-checking).
    • The module containing HeapAllocator not being properly imported or linked.
    • HeapAllocator not being a public or exported type from its module.
    • Version compatibility issues if using external libraries.

To fix this, consider the following:

  • Check Module Availability and Path: Ensure that the std/allocators/heap_allocator module actually exists at the expected location. If it's part of a library, confirm the library is correctly installed and accessible by your build system.
  • Correct Imports/Includes: Verify that you have the necessary import statements or include directives for the HeapAllocator type and its module in your solution.le file.
  • Build System Configuration: If you are using a build system (like Cargo for Rust, which sometimes uses "alloc" or "heap" crates), ensure it's configured to include and link against the std/allocators module or the specific HeapAllocator type.
  • Spelling and Casing: Double-check that HeapAllocator is spelled and cased exactly as defined in its source.
  • Compatibility: If HeapAllocator is from an external source, ensure its version is compatible with your project's other dependencies and compiโ€ฆ

-# Response generated by gemini-2.5-flash. AI may be incorrect or misleading.

hoary mirage
#

vai help me

spring lionBOT
# hoary mirage vai help me

Hello! How can I help you? I'm here to assist with Vencord-related questions, or anything else you might need. Please tell me what you're looking for!

-# Response generated by gemini-2.5-flash. AI may be incorrect or misleading.

robust yacht
#

how compile with max optimization

hoary mirage
#

my code works on example

lusty atlas
hoary mirage
#

HOWEVER ON REAL INPUT IT ALL BECOMES ONE GIANT CIRCUT AT LIKE INDX 993

robust yacht
#

ok faster now

hoary mirage
#

@native maple help

robust yacht
#

i just switched to performance plan

lusty atlas
hoary mirage
#

USING PYTHON

lusty atlas
#

good

native maple
#

your computer is just bad

robust yacht
#

nop

native maple
#

wait try run it with arena allocator again

#

maybe it was just a fluke

#

just get rid of the heap allocator stuff run with --nogc tho

lusty atlas
lusty atlas
hoary mirage
#

@native maple can I not merge circuits

native maple
#

you can

hoary mirage
#

THEN WHY DOES IT ALL BECOME ONE HUGE CIRCIUT

cloud girderBOT
robust yacht
native maple
#

i did that originally

robust yacht
#

same thing

robust yacht
#

rosie is allergic to readable variable names

native maple
#

no its pretty readable..

robust yacht
#

what is the d in d1

native maple
#

wow

hoary mirage
#

well it doesnt work

native maple
#

congrats

hoary mirage
#

no need to spoiler

#

anyway rosie fix soon

robust yacht
#

rosie fix

cloud girderBOT
# native maple <@289556910426816513> fix https://github.com/acquitelol/elle/blob/rewrite/std/ru...

arena.le: Lines 69-84

fn ArenaAllocator::realloc(ArenaAllocator *self, void *ptr, i32 _new_size) {
    // if nil is passed assume its an allocation instead of reallocation
    if !ptr {
        return self.alloc(_new_size);
    }

    // else alloc and copy old data
    let new_size = __internal_alloc_align8(_new_size);
    let new_ptr = self.alloc(new_size);

    // copy memory from old buffer to new buffer
    mem::memcpy(new_ptr, ptr, _new_size);

    // do NOT free, managed by arena allocator
    return new_ptr;
}
robust yacht
#

okay

native maple
#

thanks

#

i have a feeling memcpy is somehow causing the crash

#

since it fails in ?? in libc going straight from ArenaAllocator::realloc

robust yacht
#

maybe bounds check wrong

native maple
#

which means somehow my new size is wrong

#

what bounds check

robust yacht
native maple
#

oh i see

#

well thats wrong but idk why thats causing a bus error there

robust yacht
#

ive never seen a bus error

#

rosie trying to read my password from ram

native maple
#

i see the issue

#

memcpy is copying from the old ptr more memory than was allocated

#

mem::memcpy(new_ptr, ptr, new_size);

robust yacht
#

FIX

native maple
#

its copying new_size bytes but ptr is smaller than that

#

idk how to keep track of that

robust yacht
#

wdym

#

oh

#

that responsibly would be on the caller wouldnt it though?

#

wait

native maple
#

no

robust yacht
#

is your memcpy(src, dst, size) or dst src size

native maple
#

its dst src size

#

but ptr is the old buffer

#

which is smaller than new_ptr

#

but its copying new_size

#

so its copying memory out of bounds from ptr

robust yacht
#

new_size is how many bytes to copy

native maple
#

i know how to fix

native maple
#

but thats new_ptr's size

#

ptr is smaller which is the src

#

so its copying extra bytes

robust yacht
native maple
#

no lol because you would call realloc with a bigger size than the old buffer

#

thats how any dynamic data structure is implemented

robust yacht
#

idk it seems wrong to me

native maple
#

i just need to copy the size of the old ptr instead and leave the extra space uninitialized

robust yacht
#

idk

#

do

#

roinga

native maple
dusky frost
#

good results

native maple
#

success

cloud iron
#

i don't like d8p1

#

starts out by being annoying

native maple
#

ok @robust yacht pull from elle and rebuild and then try now

robust yacht
#

okay

#

it works @native maple

native maple
#

cool

#

i just allocate an extra i64 to store the size of the allocation and then do pointer arithmetic to go back and get that size when you realloc lol

robust yacht
#

roingaaa ๐Ÿ˜ญ

lusty atlas
#

does it keep all allocations until the program exits

hoary mirage
#

That's the right answer! You are one gold star closer to decorating the North Pole.

#

looove

lusty atlas
#

insane

hoary mirage
#

2.4 sec both parts

robust yacht
#

slow

hoary mirage
#

ITS PYTHON WHAT DO I DO

robust yacht
#

idk

hoary mirage
#

wait using python3 is faster

#

1.6 secs

lusty atlas
#

oh my god today is insane

#

actually not too bad ig

hoary mirage
#

only insane if ur huge noob

#

eric so bad

#

The next two junction boxes are 431,825,988 and 425,690,689. Because these two junction boxes were already in the same circuit, nothing happens!

#

this line

#

worst

#

you still gotta count it

cloud iron
lusty atlas
#

i think today p1 very easy

#

but will go toilert first

robust yacht
#

wtf how does the example end up with 11 circuits after making 10 connections

#

??

hoary mirage
hoary mirage
native maple
#

because the program runtime is short

hoary mirage
#

Until merged

native maple
#

the intended use of the arena allocator is to create multiple and free them individually

cloud iron
# robust yacht wtf how does the example end up with `11` circuits after making `10` connections
lusty atlas
#

OS will handle ykyk

hoary mirage
#

Elle memory leak

robust yacht
#

oh do i need to fill the circuits with each junction box initially on its own circuit then merge

lusty atlas
hoary mirage
#

You choose

#

If ur gonna start with 0 circuits it doesnt matter

#

Ignore 11 part

cloud iron
#

so today is a wikipedia day for me

hoary mirage
#

What are these words

#

Eagely alt

lusty atlas
#

do circuits have to be one straight line or can they be funny shape

native maple
# lusty atlas why even free then exit without freeing anything

youre meant to use it like this

fn main() {
    // the base arena exists by default
    for i in 0..100 { // the iterator allocates
        #set_allocator(arena := ArenaAllocator::new());
        do_expensive_thing();
        arena.free_self();
        #reset_allocator();
    }
}
``` it just so happens that i dont create any temporary arenas
cloud iron
#

funni shape

native maple
#

but the intended usecase of them is that

hoary mirage
#

There is no funny shape

robust yacht
#

share

native maple
#

and if you dont use gc, there is just one big arena by default

cloud iron
#

there's even a nice visualization on reddit

lusty atlas
#

so you can connect to circuits in the middle

hoary mirage
#

It doesnt matter

#

You will add them to same circuit

robust yacht
#

how close

hoary mirage
#

@lusty atlas solve already its been 3 yeras

native maple
#

@hoary mirage solve already its been 4 years

hoary mirage
#

both parts :)

native maple
#

how fast @hoary mirage

hoary mirage
native maple
#

husk

hoary mirage
#

DONT HUSK

#

ITS PYTHON

native maple
#

hold on ill make a fast python solution quickly

native maple
#

@hoary mirage

#

rewrote my elle solution into python

#

this is so funny

if step == 999:
    total[0] = math.prod(count for _, count in Counter(find(circuits, c) for c in range(len(circuits))).most_common(3))
hoary mirage
#

rosie explodeeew

lusty atlas
#

guhhh i hate when i get wrong for input but not example

#

what edge cases does it have

lusty atlas
#

nop did

hoary mirage
#

โ˜Ÿโ˜Ÿ Awesome T-Shirts! Sponsors! Books! โ˜Ÿโ˜Ÿ

Episode details: https://github.com/lefticus/cpp_weekly/issues/505

T-SHIRTS AVAILABLE!

โ–บ The best C++ T-Shirts anywhere! https://jason-turner-shop.fourthwall.com/

WANT MORE JASON?

โ–บ My Training Classes: http://emptycrate.com/training.html
โ–บ Follow me on twitter: https://twitter.com/lef...

โ–ถ Play video
lusty atlas
#

my solution is correct i am just running into crystal weirdness

#

ohhhhhhhhh

#

god how did i not think of this

lusty atlas
# lusty atlas god how did i not think of this

|| I was using a Map of points to circuit pointers. Then when two points are already different circuits, I just update one of the pointers to the other one's circuit. That worked but now the same circuit was made up of two pointers, so if that same circuit got changed again only some of the pointers got updated ||

native maple
#

@robust yacht you never sent how fast my elle solution is with fixed arena

hoary mirage
#

I would like to tell all my connections I ate yogurt

lusty atlas
#

i cleaned up my p1 and lol i only took 20 seconds to add p2

verbal parrot
#

how fast

#

is ur

#

solution

#

why am i

#

typing like that

native maple
verbal parrot
#

okay mine is not that bad

native maple
#

so far on track to get all solutions running in under 1s cumulatively

#

im at 300ms/1s

#

only 4 days left

verbal parrot
#

i guess i can make mine faster by using bubble sort. or even better using that data structure queue set something something

native maple
#

whats ur solution in

verbal parrot
#

go

verbal parrot
verbal parrot
native maple
#

there are just better sorts in general

verbal parrot
#

oh?

#

i only know bubble sort fr

native maple
#

it likely switches between insertion sort and quicksort depending on the size of the array

lusty atlas
native maple
native maple
#

i think

#

test :3

verbal parrot
#

i hope tomorrow will be easier ๐Ÿ˜…

lusty atlas
#

I initially had a smarter solution but i decided it's too complicated so I just switched to using one single 2d array and always finding index

verbal parrot
#

yeah i saw

lusty atlas
#

โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•[solution.le:23:14]โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•
Identifier 'MinHeap' isn't a struct or primitive type.
Are you sure you spelt 'MinHeap' correctly?

23 | dists := MinHeap::new<(f32, u64, u64)>(fn(a, b) #cast(i64, a.x - b.x));
^~~~~~~

#

guhhh do i have to upgrade elle again

native maple
#

yes

lusty atlas
#

bloat

#

โฏ ellec solution.le --nogc
ERROR: qbe:./.build-solution/target.ssa:4878: identifier too long

Compilation of 'solution.le' finished with errors. (ใฃโ—žโ€ธโ—Ÿ c)

#

peak

native maple
#

you can just git pull && make install-std install-runtime to update the stdlib

hoary mirage
#

add elle to fedora repos

#

so ven dont need to bother

verbal parrot
#

add to HOMEBREW

hoary mirage
#

elle to winget

native maple
#

vee if you have qbe cloned locally you can just like, double NString to 160 in all.h and rebuild

verbal parrot
#

play market? ๐Ÿ˜…

#

google play*

native maple
#

im gonna start shipping a qbe fork along with elle soon

#

that way i can build qbe side by side and install both at once

lusty atlas
cloud iron
vestal owl
vestal owl
hoary mirage
#

stop using clash royale language

native maple
#

crystal nesting so unreadable

lusty atlas
#

because it uses 2 spaces?

#

yeah i hate it but idc enough to bother to change it

native maple
lusty atlas
#

i tried switching to set but same perf

native maple
#

you can actually stop early when the distance gets far enough away from the best distance

lusty atlas
#

wdym?

native maple
#

consider

#

i use length_sq so i have bdist * 400 but it would be bdist * 20 if you used just euclidean distance

lusty atlas
#

no idea what u just said

native maple
#

i guess try implement this

if dist < bdist { bdist = dist; }
else if dist > bdist * 400 { continue; }
``` and see if its faster
#

i also use a min heap instead of a normal array with sort at the end, its like 12ms faster for me

lusty atlas
#

wtf is bdist

native maple
#

its inf by default

#

uhh but change it to bdist * 20 since youre calculating the distance not distance squared

lusty atlas
#

wtf is bdist ๐Ÿ˜ญ

native maple
#

best distance holds the smallest square distance between 2 boxes

#

so if you calculate the distance between the boxes and theyre really far away (relative to the best distance) you can discard that pair early

robust yacht
#

@native maple hii

lusty atlas
native maple
#

they do for the sorting tho

lusty atlas
#

๐Ÿ˜ญ

#

but this feels like cheating

native maple
#

does pruning it really make it that much faster

lusty atlas
#

yes

native maple
#

lmao

lusty atlas
#

why is the sort so slow wtf

lusty atlas
#

with pruning it has 30293

lusty atlas
native maple
#

went up until my solution was still correct

lusty atlas
#

yeah so literal cheating like i said ๐Ÿ˜ญ

#

thanks i hate it

native maple
robust yacht
#

no

lusty atlas
#

oh i got sub 100ms without pruning

#

turns out sort_by is the same as .map().sort()

robust yacht
#

sleepy veepy

lusty atlas
#

hmm ig there isn't a better way because you need to call the block multiple times otherwise

lusty atlas
#

even worse

robust yacht
#

im never gonna get d8p1

#

ugh

#

nonstop interruptions messing up my focus

#

fuebfb

lusty atlas
#

@robust yacht

frigid socket
#

d8p1 looking so difficult

#

vai if 1000 points and I need to calculate the distance between every possible combination how many combinations

#

1000*1000

spring lionBOT
lusty atlas
#

the answer is 500k combinations

frigid socket
#

so such a solution will inevitably take ages to resolve

#

and i canโ€™t use typescript

robust yacht
#

@frigid socket explain d8 to me

verbal parrot
robust yacht
#

faint insane

urban ginkgoBOT
#

@frigid socket, <t:1765196970:R>: โ€ฆ

frigid socket
#

if youโ€™re so smart

#

faint btw

#

@verbal parrot ?

#

or @native maple

#

i have absolutely no idea on how to write a sane solution

feral valve
#

guh i've got a bug i cant find

feral valve
#

my solution is like 200 lines husk

#

and also OCaml doesnt have built in Hashsets

#

ts pmo

verbal parrot
#

Any ideas?

frigid socket
#

faint im serious

#

i cannot figure it out for the life of me'

feral valve
#

this is just like ugly, i dont enjoy writing code like this

lusty atlas
#

create an array containing all possible 500k pairs. sort them by their distance

then loop over it

frigid socket
#

so there is no other way than making 500k pairs

#

๐Ÿ˜ญ

#

This will be so slow

verbal parrot
frigid socket
#

@lusty atlas did you just give up on crystal lsp

#

going so insane

lusty atlas
#

wdym

lusty atlas
#

you only have to check the first 10k pairs or so

#

the slowest part is sorting the 500k element array

#

crystal does it in 80ms

#

you can cheat by discarding any pairs whose distance is 20x bigger than the smallest distance

#

still correct solution

lusty atlas
#

basically same i wrote

#

but mine is shorter

feral valve
#

I rewrote it into a union find

#

every aoc i learn about new data structures

pale stirrup
#

only one you need to know is 2d matrix

#

they love them

lusty atlas
#

tf is Array.blit

pale stirrup
#

lc.g crystal Array.blit

prime sphinxBOT
pale stirrup
#

is it a custom function or something

lusty atlas
#

that is not crystal

#

bro is using some functional language

pale stirrup
#

made a false assumption ig

lusty atlas
#

ocaml