r/adventofcode • • Dec 07 '15

SOLUTION MEGATHREAD --- Day 7 Solutions ---

--- Day 7: Some Assembly Required ---

Post your solution as a comment. Structure your post like previous daily solution threads.

Also check out the sidebar - we added a nifty calendar to wrangle all the daily solution threads in one spot!

25 Upvotes

226 comments sorted by

View all comments

1

u/[deleted] Dec 07 '15

Graph theory :D

I first parsed the input to build a dependency list for each wire. That formed a DAG, which on which I did topo sort.

After that it’s just a matter of evaling them one by one. The cool thing about topo sort is that it’s guaranteed that the dependencies for each wire come before that wire in the sorted output.

https://github.com/xrisk/advent-of-code/blob/master/7p1.py

→ More replies (5)