11"""Day 23: LAN Party
22
3- Analyze player connections and find gaming groups in a network .
3+ This module provides the solution for Advent of Code 2024 - Day 23 .
44
5- This module solves a puzzle about identifying gaming configurations
6- based on network connections and group composition rules.
5+ It solves a puzzle about identifying groups of interconnected computers at a
6+ LAN party. The puzzle involves finding sets of computers that are all directly
7+ connected to each other (cliques) and locating the Chief Historian based on
8+ computer naming patterns.
9+
10+ The solution uses graph theory to analyze network connections, finding both
11+ small gaming groups (trios) that include specific computers and the largest
12+ possible fully-connected group representing the actual LAN party location.
13+
14+ The module contains a Solution class that inherits from SolutionBase and
15+ implements methods using NetworkX to find cliques in the connection graph.
716"""
817
918from itertools import combinations
1423
1524
1625class Solution (SolutionBase ):
17- """Solution for Advent of Code 2024 - Day 23: LAN Party.
18-
19- This class solves a puzzle about analyzing LAN party connections and finding
20- gaming groups. Part 1 identifies valid gaming trios including teachers, while
21- Part 2 finds the largest possible gaming group.
22-
23- Input format:
24- - List of connections, one per line
25- - Each line contains two node IDs separated by a hyphen
26- - Node IDs starting with 't' represent teachers
27- - All other nodes represent students
28- - Connections indicate which players can directly play together
26+ """Analyze computer networks and find LAN party groups using graph theory.
27+
28+ This solution implements clique detection algorithms:
29+ - Part 1: Count trios of interconnected computers with Chief Historian hint
30+ - Part 2: Find the largest fully-connected group (maximum clique)
31+
32+ The solution uses NetworkX graph library to model the network and efficiently
33+ find all cliques, which represent groups of computers that can all directly
34+ communicate with each other.
2935 """
3036
3137 def construct_graph (self , data : list [str ]) -> nx .Graph :
32- """Construct a NetworkX graph from the input connection data.
38+ """Construct an undirected graph from connection data.
3339
34- Creates an undirected graph where nodes represent players and edges
35- represent possible direct connections for gaming.
40+ Creates a NetworkX graph where nodes represent computers and edges
41+ represent direct network connections between them. Each connection
42+ is bidirectional.
3643
3744 Args:
38- data: List of strings, each containing two node IDs separated by a hyphen
45+ data (list[str]) : List of connection strings in format "id1-id2"
3946
4047 Returns
4148 -------
42- NetworkX Graph object representing the connection network
49+ NetworkX Graph object representing the computer network
4350 """
4451 graph : nx .Graph = nx .Graph ()
4552 edges = []
@@ -50,20 +57,18 @@ def construct_graph(self, data: list[str]) -> nx.Graph:
5057 return graph
5158
5259 def part1 (self , data : list [str ]) -> int :
53- """Count valid gaming trios that include at least one teacher .
60+ """Count sets of three interconnected computers including the Chief Historian .
5461
55- Analyzes the connection graph to find all possible groups of three
56- players that:
57- 1. Are fully connected (form a clique)
58- 2. Include at least one teacher (node starting with 't')
59- 3. Can play together based on direct connections
62+ Finds all groups of three computers that are fully connected (each computer
63+ connected to the other two) and include at least one computer whose name
64+ starts with 't' (indicating the Chief Historian's potential location).
6065
6166 Args:
62- data: List of strings representing player connections
67+ data (list[str]) : List of connection strings representing the network
6368
6469 Returns
6570 -------
66- Number of unique valid gaming trios
71+ Number of unique trios containing at least one computer starting with 't'
6772 """
6873 graph = self .construct_graph (data )
6974 teacher_cliques = [
@@ -82,19 +87,18 @@ def part1(self, data: list[str]) -> int:
8287 )
8388
8489 def part2 (self , data : list [str ]) -> str :
85- """Find the largest possible gaming group.
90+ """Find the password by identifying the largest LAN party group.
8691
87- Identifies the maximum clique in the connection graph, representing
88- the largest group of players that can all play together directly.
89- Returns the players in alphabetical order as a comma-separated string .
92+ Locates the maximum clique in the network graph, representing the largest
93+ set of computers where every computer is directly connected to every other
94+ computer. Returns the sorted computer names as a comma-separated password .
9095
9196 Args:
92- data: List of strings representing player connections
97+ data (list[str]) : List of connection strings representing the network
9398
9499 Returns
95100 -------
96- Comma-separated string of player IDs in the largest gaming group,
97- sorted alphabetically
101+ Password string of alphabetically sorted computer IDs joined by commas
98102 """
99103 graph = self .construct_graph (data )
100104 largest_clique = max (nx .find_cliques (graph ), key = len )
0 commit comments