Refactor 2023 for new system.

This commit is contained in:
Mikael CAPELLE
2024-12-04 17:09:24 +01:00
parent a9bcf9ef8f
commit 664dcfe7ba
24 changed files with 1119 additions and 1085 deletions

View File

@@ -1,25 +1,23 @@
import sys
from typing import Any, Iterator
import networkx as nx
components = {
(p := line.split(": "))[0]: p[1].split() for line in sys.stdin.read().splitlines()
}
from ..base import BaseSolver
targets = {t for c in components for t in components[c] if t not in components}
graph = nx.Graph()
graph.add_edges_from((u, v) for u, vs in components.items() for v in vs)
class Solver(BaseSolver):
def solve(self, input: str) -> Iterator[Any]:
components = {
(p := line.split(": "))[0]: p[1].split() for line in input.splitlines()
}
cut = nx.minimum_edge_cut(graph)
graph.remove_edges_from(cut)
graph: "nx.Graph[str]" = nx.Graph()
graph.add_edges_from((u, v) for u, vs in components.items() for v in vs)
c1, c2 = nx.connected_components(graph)
cut = nx.minimum_edge_cut(graph)
graph.remove_edges_from(cut)
# part 1
answer_1 = len(c1) * len(c2)
print(f"answer 1 is {answer_1}")
c1, c2 = nx.connected_components(graph)
# part 2
answer_2 = ...
print(f"answer 2 is {answer_2}")
# part 1
yield len(c1) * len(c2)