diff --git a/2024/23/index.html b/2024/23/index.html index 7f6be51d..548c2904 100644 --- a/2024/23/index.html +++ b/2024/23/index.html @@ -283,7 +283,7 @@
The network map provides a list of every connection between two computers. For example:
Visit the website for the full story and full puzzle description.
We tackled a graph algorithm problem today, where we had to find maximal cliques in an undirected graph. The literature provides efficient algorithms for this problem, but our graph is not too large, so we can use a straightforward "poor man's" strategy as well.
-I started with the seed components, that is single element components for each node that starts with 't'. Then, I proceeded to grow these components by adding a single node to them in all possible ways. I can put this in a loop, to get components with size 2, 3, 4, etc. Part 1 asks for the number of components that have 3 nodes. Part 2 asks for the one that cannot be grown anymore.
+I started with the seed components, that is single element components for each node. Then, I proceeded to grow these components by adding a single node to them in all possible ways. I can put this in a loop, to get components with size 2, 3, 4, etc. Part 1 asks for the number of components that have 3 nodes and have at least one node starting with 't'. Part 2 asks for the biggest component that cannot be grown anymore.
namespace AdventOfCode.Y2024.Day23;
@@ -301,7 +301,7 @@ LAN Party
var components = GetSeed(g);
components = Grow(g, components);
components = Grow(g, components);
- return components.Count;
+ return components.Count(c => Members(c).Any(m=>m.StartsWith("t")));
}
public object PartTwo(string input) {
@@ -313,10 +313,10 @@ LAN Party
return components.Single();
}
- HashSet<Component> GetSeed(Graph g) => g.Keys.Where(k=>k.StartsWith("t")).ToHashSet();
+ HashSet<Component> GetSeed(Graph g) => g.Keys.ToHashSet();
HashSet<Component> Grow(Graph g, HashSet<Component> components) => (
- from c in components
+ from c in components.AsParallel()
let members = Members(c)
from neighbour in members.SelectMany(m => g[m]).Distinct()
where !members.Contains(neighbour)