Skip to content

Commit b8b2c70

Browse files
committed
2024/23
1 parent ff5cc4b commit b8b2c70

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

2024/Day23/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ _Visit the website for the full story and [full puzzle](https://adventofcode.com
77

88
We tackled a graph algorithm problem today, where we had to find maximal cliques in an undirected graph. The literature provides [efficient algorithms](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm) for this problem, but our graph is not too large, so we can use a straightforward "poor man's" strategy as well.
99

10-
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.
10+
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.

2024/Day23/Solution.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public object PartOne(string input) {
1414
var components = GetSeed(g);
1515
components = Grow(g, components);
1616
components = Grow(g, components);
17-
return components.Count;
17+
return components.Count(c => Members(c).Any(m=>m.StartsWith("t")));
1818
}
1919

2020
public object PartTwo(string input) {
@@ -26,10 +26,10 @@ public object PartTwo(string input) {
2626
return components.Single();
2727
}
2828

29-
HashSet<Component> GetSeed(Graph g) => g.Keys.Where(k=>k.StartsWith("t")).ToHashSet();
29+
HashSet<Component> GetSeed(Graph g) => g.Keys.ToHashSet();
3030

3131
HashSet<Component> Grow(Graph g, HashSet<Component> components) => (
32-
from c in components
32+
from c in components.AsParallel()
3333
let members = Members(c)
3434
from neighbour in members.SelectMany(m => g[m]).Distinct()
3535
where !members.Contains(neighbour)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy