BasketMC

Signal Divider, Episode 14: TIS-100

  • Published on

Episode 14 opens Signal Divider, a puzzle that asks for division with a quotient and a remainder. Basket builds a loop that subtracts until it goes negative, gets it to pass in seven nodes, and then spends the rest of the video rebuilding it in six. Both versions pass by the end.

Division by subtraction

The task panel reads: "Read values from IN.A and IN.B. Divide IN.A by IN.B. Write the quotient to OUT.Q. Write the remainder to OUT.R." The commentary checks the first row, 47 and 3, against the answers, 15 with a remainder of 2, and settles on a plan: "keep on subtracting three", count how many times that worked, and find out what is left.

TIS-100 Signal Divider puzzle with every node empty: the task panel asks to read values from IN.A and IN.B, divide IN.A by IN.B, and write the quotient to OUT.Q and the remainder to OUT.R, beside the four number columns, two stack memory nodes and a red node marked COMMUNICATION FAILURE.

A count needs somewhere to live, so Basket opens Exposure Mask Viewer and finds the #WIDTH storage node. Before copying it, two lines change: "MOV RIGHT ACC" becomes "MOV ANY ACC" and the output becomes "MOV ACC LAST". On the recording, the point is to "generalize the code": "if I copy and paste it I don't have to keep on changing these lefts and rights". A quick run of the old puzzle confirms it still works.

TIS-100 editor back in Exposure Mask Viewer: the node labeled #WIDTH now reads MOV ANY ACC and MOV ACC LAST, next to the rectangle target image and the other nodes of that solved puzzle.

Seven nodes

The pasted node becomes "#B", holding the divisor, and a second copy becomes "#Q", the counter. The main loop subtracts B, and while the number stays above zero, "ADDQ: MOV 1 DOWN" adds one to the count. When it goes negative, B is added back, and what is left is the remainder.

The first run puts a 2 in the wrong spot. The remainder and the quotient come out in a different order than expected, and a zero sent down resets the count before it can be read. After those fixes the quotient is "always two": #Q was adding to the value it was sent instead of its saved count. A "SWP", "ADD", "SAV" change gets "15, 2, yes."

Run fast, the rows where the remainder is zero still fail in red. A "JEZ ADDQ" line handles them, and Signal Divider passes: 9296 cycles, 7 nodes and 40 instructions. A friend's score beside it uses six nodes and fewer instructions. "I used one more node and way more code."

TIS-100 running test 1 of Signal Divider: the OUT.Q and OUT.R columns show several wrong values marked in red, while nodes labeled #B and #Q sit beside a divide loop that starts with MOV UP RIGHT.

Six nodes

Basket copies the program and starts moving things. #B goes under IN.B and #Q under the main loop, and #B takes on more work: a negative number asks for B back, while zero or a positive number makes it pass a value down and then read the next B from the top, with a new "RESET: MOV UP ACC".

The first run sends nothing to OUT.Q. Breakpoints and stepping turn up the cause: with "MOV ANY ACC", #B was also taking values from the wrong neighbor. Changing it to "MOV LEFT ACC" gives a deadlock, because "last only gets set if you used any", so "MOV ACC LAST" becomes "MOV ACC LEFT". Then the quotients keep climbing. The count is never cleared, so the node is changed to clear it each time it sends a value down.

TIS-100 Signal Divider reworked into six nodes: the #B node under IN.B starts with RESET: MOV UP ACC, the #Q node below the divide loop starts with START:SWP, and three MOV UP DOWN nodes carry values down to OUT.Q and OUT.R.

Where it ends

Every test passes again: 9293 cycles, 6 nodes and 40 instructions. That matches the friend's node count but not the instruction count, and the commentary is curious how the shorter version was done, guessing there must be "a much easier way". The video ends on the result screen, then the end card.