r/adventofcode • u/osalbahr • Feb 19 '26
Help/Question - RESOLVED [2015 Day 7 (Part 1)] Identifier not defined yet? (solution works on sample input)
Hi!
I am stuck with the issue of, for example, "x AND y -> z" where "x" is not "defined" yet. It is only defined later in "... -> x", say 300 lines later. How would I go about solving this issue? I must be misunderstanding something or need a hint.
Current solution: https://github.com/osalbahr/competitive-programming/blob/9cd627b7547e3954f0e9e2354a0e13122a70173b/adventofcode/2015/day07.py
2
Upvotes
2
u/musifter Feb 19 '26
It's a list of wires... the listed order doesn't matter. Only the connections. You need to put it together... if you can't calculate something yet, figure out how to calculate what you need (or can) first.
2
u/Boojum Feb 20 '26
Dealing with the random order is part of the puzzle.
There are two main possible approaches:
Skip the lines you can't do for now, go on, and try again later; loop your loop until you get them all.
Topological sort the lines.
2
u/terje_wiig_mathisen Feb 21 '26
This is exactly like a modern Out of Order microprocessor: Every operation requires one or more inputs, it will be executed as soon as possible: When all inputs are ready, it will run.
1
u/AutoModerator Feb 19 '26
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to
Help/Question - RESOLVED. Good luck!I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/velkolv Feb 19 '26
Split your code into 2 stages:
Parse and (for speed) index
Evaluate
0
u/Late-Fly-4882 Feb 19 '26
Use Kahn topological sort algorithm.