diff --git a/2024-python/output/day_24.py b/2024-python/output/day_24.py index 3474478..a4b7d97 100644 --- a/2024-python/output/day_24.py +++ b/2024-python/output/day_24.py @@ -1,7 +1,12 @@ +import graphviz +import re + + def solve(data): values, wires = data.split("\n\n") values = dict([tuple(c.strip().split(": ")) for c in values.splitlines()]) - Q = [w.split() for w in wires.splitlines()] + wires = [w.split() for w in wires.splitlines()] + Q = [*wires] while Q: a, o, b, _, c = Q.pop(0) if a not in values or b not in values: @@ -25,10 +30,38 @@ def solve(data): ), 2, ) - p2 = None + # render_graph(wires) + wrong_xors_inputs = r"[^y|x]\S{2}+ XOR [^x|y]\S{2}+ -> ([^z]\S{2})" + wrong_z_outputs = r"\s(?:OR|AND) .+ -> (z\d{2})" + found_manually = ["jqf", "skh"] + p2 = ",".join( + sorted( + [seq for seq in re.findall(wrong_z_outputs, data) if not seq.endswith("45")] + + list(re.findall(wrong_xors_inputs, data)) + + found_manually + ) + ) return p1, p2 +def render_graph(wires): + dot = graphviz.Digraph(comment="The Round Table") + + for a, o, b, _, c in wires: + ol = f"{a}{b}{o}{c}" + dot.node(a) + dot.node(b) + dot.node(c) + + dot.node(ol, label=o, shape="diamond") + + dot.edge(a, ol) + dot.edge(b, ol) + dot.edge(ol, c) + + dot.render("2024.24.p2.gv").replace("\\", "/") + + if __name__ == "__main__": with open("./input/24.txt", "r") as f: inp = f.read().strip() @@ -37,6 +70,3 @@ if __name__ == "__main__": print(p1) print(p2) - - assert p1 == 36035961805936 - # assert p2 == 0