You are at the Easter bunny HQ again, they are holding a LAN party.
You download a map of their network, that’s your input.
An example input looks like this:
Each line describes a connection between two computer names.
The connections don’t have a direction, so the first line means:
kh connects to tc
tc connects to kh
In other words, the network is a graph with a bunch of undirected edges.
Get ready for a graph theory problem!
Parsing
Creating the graph.
Part 1
The chief historian might be participating, their computer name starts with a t.
Start by looking for sets of 3 computers that are all connected to each other where at least 1 name starts with a t.
The question asks how many cliques of 3 contain a computer that starts with a t.
Part 2
Now find the largest clique in the graph.
The password is the alphbetically sorted names of all computers in the LAN party.
The question asks what the password is.
During my initial solve, I used a method that gave me the right answer, but turns out to be technically incorrect because it relies on the graph structure.
The input happened to be constructed in a way that made my code work (and as far as I can tell, works on everyones input).
I’ll list it here too, but first, the way I should have done it.
There exists an algorithm for finding the largest clique in a graph with undirected edges: the Bron-Kerbosch algorithm.
I dislike 1 letter variable names, so I gave them a more descriptive name.
The comment above the helper is from wikipedia.
Bonus: faster, but maybe incomplete
My original code, it works, but only because the input is crafted for it to work.