BasketMC

Sequence Indexer Part 3, Episode 17: TIS-100

  • Published on

Episode 17 is the third video on the Sequence Indexer. It opens in the editor with the code Episode 16 ended on: two stack memory nodes, a -1 ready signal and a preloaded zero. Basket talks through the signals between nodes, runs out of lines, rewrites the lookup to save one, and steps through a test. The first number out is right, but the puzzle is still unsolved when the video ends.

Talking through the signals

The task panel still reads: "Sequences are zero-terminated. Read a sequence from IN.V. Read index values from IN.X. Look up index value in sequence. Write indexed value to OUT." The top left node fills the top stack, and the bottom left node preloads a zero with "MOV 0 RIGHT" and ends with "GO: MOV -1 UP."

TIS-100 Sequence Indexer in the editor: the task panel lists the five rules, the top left node holds MOV 0 RIGHT and a START loop, the bottom left node preloads a zero and ends with GO: MOV -1 UP, and the center node holds the lookup with L1, L2 and DONTSEND labels.

The first nine minutes go into who waits for whom. "Basically, either I'm moving the stuff down or this thing is processing stuff, but not both." A -1 sent across means "move the stuff down," and the center node's lookup now starts with "L1: MOV -1 LEFT" so it can hand the turn back. Then the reading side needs a zero on top first, "and I'm out of lines of code."

One line shorter

The commentary looks for a line to cut in the lookup. The idea is to subtract from the index before checking it, so the swaps can go. The rewrite goes into the empty node at the right of the middle row, with "SUB 1" ahead of "JGZ DONTSEND." Later, "JRO 2" goes in after the send to skip the next command: "I think technically you can do this." The node under IN.X becomes "MOV UP ACC," "ADD 1," "MOV ACC DOWN."

TIS-100 Sequence Indexer with two versions of the lookup: the original in the center node and a rewrite in the right-hand middle node that starts L1: MOV -1 LEFT and runs SUB 1 before JGZ DONTSEND, while the node under IN.X reads MOV UP ACC, ADD 1, MOV ACC DOWN.

At about 16 minutes the commentary stops: the whole reason for the rearranging was to signal when the lookup is done, "but I've already built that in up here." The new code stays where it is, unused for now.

Stepping through

The run fills the top stack "in kind of the wrong order," and the zero in the bottom stack is "on purpose." The -1 goes up, the values pour into the bottom stack in reverse, and the lookup starts. At about 19:40, 860 shows up in the OUT column, matching the first expected value. Right after that: "Oh, it's also going to deadlock." The lookup takes the -1 for a value to send, and there is still no zero at the end of the new list.

TIS-100 Sequence Indexer paused during test 1: OUT has received 860, the first expected value, the bottom stack memory node holds the sequence in reverse with a 0 on top, and a SWP line is highlighted in the center node.

The missing word

Basket moves the shorter lookup into the center node, adds "MOV 0 UP" to preload that zero, "to be the end of the new string," and swaps the check for "JEZ SEND" with a SEND label. The old version is kept as a backup in the bottom right node. Stepping through, the top stack now holds only the zero, and the commentary sees why nothing comes back: "So I never get the value from down below. Yeah, the word down doesn't appear in my code. Well, that's an oversight."

TIS-100 Sequence Indexer stepping through test 1: the top stack memory node holds a single preloaded 0, the bottom stack holds the reversed sequence, the center node has a breakpoint on MOV 0 UP with JEZ SEND highlighted, and OUT is still empty.

Where it ends

No test passes. "This is probably episode two on the same problem, or even three." The commentary is "out of space" and wants "to figure out another solution," and the video fades to the end card with the Sequence Indexer still open.