# 2024 Day 23: LAN Party

**URL:** https://forum.ada-lang.io/t/2024-day-23-lan-party/1682
**Category:** Advent of Code
**Tags:** spoilers
**Created:** [January 4, 2025, 5:06am UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682 "2025-01-04T05:06:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)
#### Post date: [January 4, 2025, 5:06am UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682/1 "2025-01-04T05:06:51Z")

</div>

Part 1 is mostly straightforward. Several people on Reddit say they solved Part 2 using depth-first search and/or recursion, but I encountered combinatorial explosion when I tried that, so I spent my time looking for other approaches. (Caching would probably make it work, but I didn’t feel like figuring out how to implement that.) I tried a Monte-Carlo approach, but I quickly realized that the data was set up so that this would be like looking for a needle in a haystack.

On Reddit a lot of users implemented [the Bron-Kerbosch algorithm](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm), which not only had I never heard of, neither did a professional graph theorist.

My Monte-Carlo approach wasn’t a complete waste of time, in that I noticed it was consistently producing LANs with 12 computers. There were only 13 possible connections from any one computer, and the puzzle makes it clear that all the computers in a LAN _are connected to each other_, so the correct answer couldn’t have had more than 14 computers (1 + its 13 listed connections) – and that was unlikely, so it had to be a network of 13. Nevertheless, I didn’t look precisely for that; what I did was take each set S of connections from a node; for each element of S count how many other elements of S it was connected to, and if the result was consistent (i.e., the number of elements w/the maximal number of connections was in fact that number of connections) then save that, keeping the largest saved set.

I’m not actually sure it’s correct in all cases, but it worked here, and the same graph theorist I mentioned above on Reddit described a similar approach, at least in principle, even producing a proof that it works under the given assumptions, so… 🤷 On to [day 24](https://forum.ada-lang.io/t/2024-day-24-crossed-wires/1671) I reckon… but [the stats suggest](https://adventofcode.com/2024/leaderboard/day/24) that’s another murderous problem, so I’ll have to put it off another day or more.

---

<div class="post-metadata">

### Author: ![tgv](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/tgv/32/548_2.png) [@tgv](https://forum.ada-lang.io/u/tgv)
#### Post date: [January 4, 2025, 3:38pm UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682/2 "2025-01-04T15:38:24Z")

</div>

I used a simple flooding algorithm, because I think the text makes it clear that in the cluster all computers are connected to each other. There are no interconnected clusters. That makes the aforementioned algorithm overkill.

---

<div class="post-metadata">

### Author: ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)
#### Post date: [January 4, 2025, 9:17pm UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682/3 "2025-01-04T21:17:28Z")

</div>

Did you loop throug the nodes and start the flood from each?

I think some LANs are connected to each other, though. In the example, `wh` is connected to 4 other nodes, each of which is on a separate LAN. So I must misunderstand something you’re saying.

---

<div class="post-metadata">

### Author: ![jcmoyer](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/jcmoyer/32/373_2.png) [@jcmoyer](https://forum.ada-lang.io/u/jcmoyer)
#### Post date: [January 5, 2025, 7:12am UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682/4 "2025-01-05T07:12:18Z")

</div>

I solved this one accidentally by summing the neighboring rows for each row in an adjacency matrix and printing the result. One of the rows had a single 13 and many 12’s, so I just regex searched `12.*?12.*?12.*?12.*?12.*?...` adding 12’s until no matches and noted the names, which turned out to be the correct answer. I think this only happened to work because the input data isn’t very noisy. If Eric had put many random connections between nodes the pattern wouldn’t be so obvious.

---

<div class="post-metadata">

### Author: ![zertovitch](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zertovitch/32/90_2.png) [@zertovitch](https://forum.ada-lang.io/u/zertovitch)
#### Post date: [January 5, 2025, 10:57am UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682/5 "2025-01-05T10:57:36Z")

</div>

I did both parts with naive algorithms and luckily it runs fast enough: 1 sec with HAC, 0.06 sec with GNAT, Debug mode, 0.03 with GNAT, Fast\_Unchecked mode.

---

<div class="post-metadata">

### Author: ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)
#### Post date: [January 6, 2025, 12:33am UTC](https://forum.ada-lang.io/t/2024-day-23-lan-party/1682/6 "2025-01-06T00:33:39Z")

</div>

Between you and @tgv I’m starting to think that I should have used a breadth-first-search algorithm.
