BasketMC

Sequence Counter, Episode 3: TIS-100

  • Published on

Episode 3 opens on the segment map with Sequence Counter, the segment named in the title, and the commentary says the aim is to beat a friend's scores. Basket passes Sequence Counter with fewer nodes and instructions than that friend, then moves straight on to Signal Edge Detector and passes it too before the video ends.

Sums and lengths

Sequence Counter's panel reads: "Sequences are zero-terminated. Read a sequence from IN. Write the sum to OUT.S. Write the length to OUT.L." The friend's line on the segment map shows 317 cycles, 6 nodes and 28 instructions. Planning the first node goes slowly: "this is more complicated than I thought because I only have one storage spot."

The empty Sequence Counter screen: the task panel reads "Sequences are zero-terminated, read a sequence from IN, write the sum to OUT.S, write the length to OUT.L", beside the IN, OUT.S and OUT.L number columns and a grid of blank nodes with one red node marked "Communication Failure"

Saving and swapping

The answer on screen is SAV and SWP. The OUT.L node saves the count, reads a value with "MOV LEFT, ACC", jumps to a SEND label on zero with "JEZ SEND", and otherwise swaps the count back, runs "ADD 1" and loops. The OUT.S node does the same with a running sum. Under IN, a middle node sends each value down twice, so the sum node can pass one copy right to the count node and add the other.

One line eats a value

The first run marks rows of both OUT.S and OUT.L in red. "My sum ended up being zero." The commentary finds the line: under SEND, "MOV ACC, NIL" should throw away the second copy coming from above. It becomes "MOV UP, NIL," and every test passes in 336 cycles with 4 nodes and 24 instructions, against the friend's 317, 6 and 28. "I feel accomplished."

Sequence Counter running test 1 with several OUT.S and OUT.L results in red; the bottom two nodes hold programs with "START:", "SAV", "SWP", "JEZ SEND" and "SEND:" lines, one of them reading "MOV ACC, NIL"

Changes of 10 or more

Signal Edge Detector says: "Read a value from IN. Compare value to previous value. Write 1 if changed by 10 or more. If not true, write 0 instead. The first output is always 0." The friend's line shows 4 nodes and 17 instructions. The node under IN again sends each value down twice, and the next node starts with "SUB UP." The commentary wants an absolute value and tries "JRO 2" to skip a line, then replaces it with "JGZ MATH" and a "NEG" for negative changes, followed by "SUB 10."

The Signal Edge Detector editor: the task panel asks to write 1 if the value changed by 10 or more, the node under IN holds "MOV UP, ACC" and two "MOV ACC, DOWN" lines, and the node below it is being written with "SUB UP", "JRO 2" and "NEG"

Exactly 10

The first full run shows a few red rows in OUT. "It fails if it is exactly equal." The test changes from "JGZ SEND1" to "JLZ SEND0," with the 1 and 0 lines swapped to match. The next run passes in 385 cycles with 4 nodes and 14 instructions, three instructions fewer than the friend. "I'm a winner."

Signal Edge Detector running test 1 with three red results in the OUT column; the middle node holds "SUB UP", "JGZ MATH", "NEG", a "MATH:" label with "SUB 10" and "JGZ SEND1", and lines sending 0 or 1 down toward OUT

Where it ends

The Signal Edge Detector result screen stays up while the commentary closes the episode, and the video cuts to the end card with both segments passed.