r/adventofcode • • Dec 24 '24

Visualization [2024 Day 24 Part 2] Using a graph visualization tool (Mermaid) to identify suspicious wires.

140 Upvotes

18 comments sorted by

View all comments

33

u/jlhawn Dec 24 '24

So my solution to part 2 was basically to write a script to convert the input into a graph in Mermaid, then take a look at it. I know how an adder should work (because I have created a virtual arithmetic logic unit before using a tool called Logisim) so it was easy to identify what wires are swapped just by looking at it.

20

u/uristoid Dec 24 '24

Honestly? I did the same (using graphviz). It's christmas eve, I don't have the time to code an elaborate solution. Funnily enough, it's my best score for a day so far i.e. I was much faster than coding a general solution would have been.

6

u/ric2b Dec 24 '24

How do you get the Mermaid plot to look so clean? Mine is a mess of curved wires that make it really hard to see the structure of it. I'm using https://mermaid.live

3

u/jlhawn Dec 24 '24

Not sure if it matters but do some sorting first. All x and y inputs first. Then I normalize the gates so that the first input name is less than the second input.

1

u/ric2b Dec 25 '24

That did it, thanks!

1

u/luke2006 Dec 24 '24

i also struggled with mermaid, unable to have more than 500 edges. and when i did it locally, the svg wasn't easily pannable, zoomable. switched over to graphviz spitting out a png, which was slightly better, but the layout wasnt super consistent either (maybe just need to pick a different layout algo). did you face any of these issues?

5

u/burnt_heatshield Dec 24 '24

I just connected the input and output bits too (e.g. x00->x01->x02->..., and same for the y's and z's), that way Graphwiz created a clean chain: https://dreampuf.github.io/GraphvizOnline/...

2

u/E3FxGaming Dec 24 '24

unable to have more than 500 edges. and when i did it locally, the svg wasn't easily pannable, zoomable

Using mermaid-cli, I created a .stats.mermaid.json file in the same directory as the mermaid diagram file, with the following content

{
  "maxEdges": 1000000
}

Then the command to generate a png was

mmdc -i output_corrected.mmd -o output_corrected.png -c .stats.mermaid.json -w 24000 -H 24000

I picked png since it has a white background, wich was much easier to visually comprehend. Also SVG somehow did not show the text on the nodes? I'm sure you can set the background color of the svg somehow and fix the text, but for png it just works.

Gimp had no problems opening the png, I added a second layer and got to work figuring out what had to be changed. The png had a resolution of approx. 11765x21464 (~2.4 MiB), which none of my programs on Linux had a problem with.

1

u/lyon Dec 24 '24

The Neato output in graphviz was pretty good (if you can zoom out to the entire file):
http://offshore.hkolk.nl/~hkolk/graphviz-2.svg

1

u/jlhawn Dec 24 '24

I used pdf output to fix that 😆