File handling for API.
This commit is contained in:
@@ -80,22 +80,23 @@ class Solver(BaseSolver):
|
||||
outputs,
|
||||
)
|
||||
|
||||
if self.outputs:
|
||||
with open("./day20.dot", "w") as fp:
|
||||
fp.write("digraph G {\n")
|
||||
fp.write("rx [shape=circle, color=red, style=filled];\n")
|
||||
for name, (type, outputs) in self._modules.items():
|
||||
if type == "conjunction":
|
||||
shape = "diamond"
|
||||
elif type == "flip-flop":
|
||||
shape = "box"
|
||||
else:
|
||||
shape = "circle"
|
||||
fp.write(f"{name} [shape={shape}];\n")
|
||||
for name, (type, outputs) in self._modules.items():
|
||||
for output in outputs:
|
||||
fp.write(f"{name} -> {output};\n")
|
||||
fp.write("}\n")
|
||||
if self.files:
|
||||
contents = "digraph G {\n"
|
||||
contents += "rx [shape=circle, color=red, style=filled];\n"
|
||||
for name, (type, outputs) in self._modules.items():
|
||||
if type == "conjunction":
|
||||
shape = "diamond"
|
||||
elif type == "flip-flop":
|
||||
shape = "box"
|
||||
else:
|
||||
shape = "circle"
|
||||
contents += f"{name} [shape={shape}];\n"
|
||||
for name, (type, outputs) in self._modules.items():
|
||||
for output in outputs:
|
||||
contents += f"{name} -> {output};\n"
|
||||
contents += "}\n"
|
||||
|
||||
self.files.create("day20.dot", contents.encode(), False)
|
||||
|
||||
# part 1
|
||||
flip_flop_states: dict[str, Literal["on", "off"]] = {
|
||||
|
Reference in New Issue
Block a user