You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was an interesting problem, and I ended up learning a few new things. If
48
+
you define a circuit as the set of all connected junctions, then you can find
49
+
the union of the sets to which the two junction boxes you are connecting belong
50
+
in order to find the new connected circuit. The difficulty is finding an
51
+
efficient way to look up a set given one element from the set.
52
+
In my [initial solution](https://github.com/devries/advent_of_code_2025/blob/b4ecead2fd971f0fec5223da3679160b599e851e/src/day08/solution.gleam) I created a dict which had junction boxes as the key
53
+
and sets of junction boxes as the values. This meant changing the values of
54
+
all the elements in the dictionary that belonged to a set when a new union
55
+
was made. In the Gleam Discord the [disjoint-set data structure](https://en.wikipedia.org/wiki/Disjoint-set_data_structure)
56
+
came up as a way to do this more efficiently, so I decided to try it and
57
+
created a simple [disjoint-set library](src/internal/disjoint_set.gleam).
58
+
Using the new structure, and making a few other changes, the second part of
59
+
my [solution](src/day08/solution.gleam) is roughly 3 times faster.
0 commit comments