Use one node to choose which of two other nodes to send on:
0:MOV UP, ACC JLZ A JGZ B MOV LEFT, ACC ADD RIGHT MOV ACC, DOWN JMP 0 A:MOV LEFT, DOWN MOV RIGHT, NIL JMP 0 B:MOV RIGHT, DOWN MOV LEFT, NIL |
Sort two inputs before sending them on:
0:MOV UP, ACC # Get the first value to be compared SAV # Save ACC to BAK SUB LEFT # Subtract the other value it should be compared to JGZ A # If it's > 0, the LEFT value is smaller and thus we want to send it first. B:SWP # Otherwise it's <= 0 and so the UP value is the same or smaller, so we want to send it first. MOV ACC, DOWN MOV LEFT, DOWN # Note that the LEFT node needs to send its value twice. JMP 0 A:SWP # Send MOV LEFT, DOWN MOV ACC, DOWN |
Python version of the desired code:
while True: x = input() y = input() width = input() height = input() for current_y_offset in range(height): current_y_position = y + current_y_offset output(x) output(current_y_position) for current_x_offset in range(width): output(3) output(-1) |
Sub-puzzles:
(DONE #2) Read a sequence from IN, store it in a stack, and then write the zero-terminated sequence to OUT.
Without regard to the output, just store incoming elements into the stack until the stack is full.
Read the first two elements from each sequence and return them in order of increasing value.
Thoughts:
I can't think of another way that it could work *other* than that way.
General trick: if you're doing more than one thing in a node and you're running out of space, look for a way to move logic out of the node into a different one.
(SOLVED) One tricky thing is, when the code is popping from the stack, how does it deal with the case where it gets to the bottom of the stack? It seems like it would need to know how big the stack is, otherwise it'll just lock up when it tries to get a number from the empty stack.
Data that needs to be stored:
The number of elements in the sequence.
This is so that when you're outputting the sequence you'll know how many times to try to take something from the stack.
Plain-english description of how it should work:
If the number is zero, output what you've got on your sorted stack, then restart from the beginning.
If the number is not zero, pop one number at a time from the sorted stack, and compare that number to the new number.
If the new number is smaller, add the popped number back where it was popped from, then add the new number, then add all of the numbers from the temporary stack.
If the new number is larger, move it onto the "real" stack, then move the compared number, and then move the rest of the items from the temp stack onto the real stack.