Advent of code in SPL - 2025 day 8
- Gabriel Vasseur

- 6 hours ago
- 4 min read
Day 8 is here.
Part 1
So the first challenge is to enumerate all possible pairs. Let's play with very simple data to start with:
I guess eventstats is a good way to bring all of the events into each of the events:
Now we just have to mvexpand item2. But there are a couple of problems:
we can't have pairs made of twice the same event, that's not possible.
the order doesn't matter in pairs, so we need to dedup them somehow.
Cool, so now we know how to enumerate pairs. Let's apply it to the demo data:
So far so good. The next step is to order the pairs by distance and decide which ones are connected:
Note: we could be using pow(,) for the distance calculation.
So now the difficulty is in grouping the nodes in circuit. Can we use stats to do that somehow?
To simplify, let's discard all the non-connected nodes. They are each their own circuit, of size 1, so not interesting. Then let's create a multivalue of the two nodes in a connection:
Can we then use stats somehow?
Ooh that's promising. This works because if the same node is involved in more than one pair, the stats will group the pairs together.
The only trouble is we need to repeat it a few times (an unknown amount of times, unfortunately). This should be repeatable:
We can now repeat the last three lines a few times, until the number of results stop decreasing:
This is what we expect. Now we just need to identify the 3 biggest circuit and multiply their sizes together:
Not bad. It's just a shame that we had to copy-paste code and that we can't predict how many iteration is needed.
Now let's move on to the full data. We save the full data to a csv, add "x,y,z" as headers (since they are already coma separated values!) and upload it to splunk.
Let's not forget to increase the number of connections too!
Now we just need to copy paste a few iteration of the grouping code until we notice the result doesn't change any more:
Not the most elegant, but we got here in the end!
Can you think of a different way that doesn't require repeating stats an unknown amount of times?
Part 2
So in this part of the challenge, we need to count the number of circuits. Let's go back to after we've just grouped all the circuits:
First it would be nice to know for sure if we're done with the grouping, or if we need to copy-paste the grouping logic some more. To know, we just to check if a node is in more than one group. To avoid messing with our work so far, we do this in appendpipe (we can't use eventstats as we don't have one event per node). With everything tidied, we've got:
Notice how we use field formating to colour state. And if we add the grouping logic some more:
Ok, I like it.
The number of circuit is basically the number of results we have + the number of nodes that haven't been connected at all. Unfortunately we discarded the non-connected nodes. So it would be nice if we kept track of how many we had to start with:
Ok, now we just need a few calculations:
We're also using formatting for total_circuit_count (with a range).
Let's go back to the full challenge data and 1000 connections:
Note how the circuit count goes crazy (negative!) when grouping isn't done.
Need more grouping!
We're going to need a lot more connections. But how many?
We can figure out a good minimum starting point. To have only one circuit, it means that every single node must feature in at least one connection. So let's find that out.
So in this example there is no point starting lower than 29. Let's try it:
Success! We can check that 28 gives 2 circuits, so we've definitely got it.
Note: we could be unlucky, and still end up with more than one circuit. This only guarantees that the smallest circuit contains more than one node.
To get the actual challenge solution, we need to keep track of the last X's we've connected:
Let's try with the full data:
This search took 4 or 5 seconds but it did give us a good piece of information.
Let's plug that in our main search:
Oooh we were lucky. This search took two and half minutes to run as well. After checking that 6587 yield 2 circuits, we can submit our answer.
Yay!
Note: the first time I did this challenge I definitely did not find the right answer by increasing the number of connections by 1000 each time until I overshoot and then narrowing it down half by half... That would be silly! So I don't know what these notes mean but thought I'd include them:
12 circuits at 3000 links in 108 seconds.
5 at 3800 in 86 seconds (!) (interesting how it's not linear)
4 at 4200 90s
3 at 5000 114s
1 at 7500 150s!!!
5000 3
6250 2
6562 2
6581 2
6586 2
6587 2
6588 1 <- got it!
6591 1
6601 1
6640 1
6718 1
6875 1
7500 1


Comments