Skip to content

Commit

Permalink
feat: add adv_2024_23
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 committed Dec 23, 2024
1 parent 894143c commit 49f6d1c
Show file tree
Hide file tree
Showing 5 changed files with 3,453 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages = [{include = "solutions"}]
[tool.poetry.dependencies]
python = ">=3.10,<4.0.0"
numpy = "2.2.1"
networkx = "3.4.2"

[tool.poetry.group.dev]
optional = true
Expand Down
26 changes: 26 additions & 0 deletions solutions/adv_2024_23.py
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))
14 changes: 14 additions & 0 deletions tests/test_adv_2024_23.py
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"),
},
)
Loading

0 comments on commit 49f6d1c

Please sign in to comment.