TIS-100, part 2

Let's continue our TIS-100 adventure, and see if we can make it out of tutorial land today.

Segment 30647: sequence generator

This is the first puzzle that hints at how painful it is to compare two numbers with the TIS-100, which is something we will unfortunately be doing a lot in the future. As for right now, we can get away with this clunky solution.

The node reading A acts as a cache for that value. The node reading B does the actual comparison. It does this by computing B - A. If the result is less than zero, then A > B. Otherwise, B <= A. This then determines the order in which the two values are passed down. Note that after doing B - A, we add A again to get the original value of B back.

Segment 31904: sequence counter

A fairly straightforward solution. The idea is the same for both output nodes: accumulate whatever non-zero values you see, and output as soon as a zero is seen. The OUT.S node accumulates by adding the value it sees, while the OUT.L node accumulates by always adding 1.

Note that the middle-right node can trivially be removed (by having the OUT.S node pass the value to the OUT.L node), but this results in slightly more cycles.

Segment 32050: signal edge detector

Another trivial solution here. The comparison node keeps the previous value in ACC. It then computes the absolute difference with the next value (SUB, followed by NEG if the result is less than zero). It then subtracts 10. If the result is larger than zero, then no change is detected and we output zero. Otherwise, we output one.

Segment 33762: interrupt handler

Lots of copy-pasting on this one. The input nodes all work the same way: keep track of the previous value, and detect when a one is seen with the previous value being a zero. If this happens, output the node number (1, 2, 3, or 4). Output zero in all other cases. The remaining nodes then simply add all outputs together, and send the result to the final output node.