-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
3,453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import networkx # type: ignore | ||
|
||
|
||
def _parse_input(in_str: str) -> networkx.Graph: | ||
res = networkx.Graph() | ||
for _ in in_str.splitlines(): | ||
node_a, node_b = _.split("-") | ||
res.add_edge(node_a, node_b) | ||
return res | ||
|
||
|
||
def _is_chief_historian(in_list: list[str]) -> bool: | ||
return any(_.startswith("t") for _ in in_list) | ||
|
||
|
||
def solve_a(in_str: str) -> int: | ||
return sum( | ||
1 | ||
for _ in networkx.simple_cycles(_parse_input(in_str), 3) | ||
if _is_chief_historian(_) | ||
) | ||
|
||
|
||
def solve_b(in_str: str) -> str: | ||
max_clique = max(networkx.find_cliques(_parse_input(in_str)), key=len) | ||
return ",".join(sorted(max_clique)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import solutions.adv_2024_23 as sol | ||
from . import test_utils as tu | ||
|
||
|
||
_INPUTS = tu.get_inputs(23, {"small", "p"}) | ||
|
||
|
||
test_solve_a, test_solve_b = _INPUTS.get_tests( | ||
(sol.solve_a, sol.solve_b), | ||
{ | ||
"small": (7, "co,de,ka,ta"), | ||
"p": (1423, "gt,ha,ir,jn,jq,kb,lr,lt,nl,oj,pp,qh,vy"), | ||
}, | ||
) |
Oops, something went wrong.