Syscall 2: Firmware, home

SignalChapter 5: Half duplex

39PLATE STACK

The task

A value of X that is not 0 puts a plate on the stack. A 0 takes the top plate off to P.

A 0 on an empty stack sends 0. The stack never holds more than four plates.

The board

The board of PLATE STACK5 cores: h, s1, s2, s3, and s4. Inputs X; outputs P.hSC-2 15 LINESs1SC-2 15 LINESs2SC-2 15 LINESs3SC-2 15 LINESs4SC-2 15 LINESP0P1P2P0P1P0P1P0P1P0XP
The board as the puzzle screen lays it out. Cyan pins read, lemon pins write, violet pins go both ways. On a narrow screen, scroll the board sideways to see all of it.

Key idea

A stack of four cores: a push shifts plates along, a pop asks the next core with a 0.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

Each core can hold one plate. Let 0 mean the core is empty.

Hint 2Show

A new plate pushes the old top one core along. Taking one off pulls the next one back.

Hint 3Show

Ask the next core for its plate by sending it a 0.

Solution

Reveal the Full SolutionThe complete program for PLATE STACK. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

hSC-2 standard

T: IN P0
OUT P1
JNZ T
IN P1
OUT P2

s1SC-2 standard

T: MOV B, A
IN P0
JZ G
XCH A, B
JZ K
OUT P1
K: XCH A, B
JMP T
G: XCH A, B
OUT P0
JZ T
MOV A, 0
OUT P1
IN P1

s2SC-2 standard

T: MOV B, A
IN P0
JZ G
XCH A, B
JZ K
OUT P1
K: XCH A, B
JMP T
G: XCH A, B
OUT P0
JZ T
MOV A, 0
OUT P1
IN P1

s3SC-2 standard

T: MOV B, A
IN P0
JZ G
XCH A, B
JZ K
OUT P1
K: XCH A, B
JMP T
G: XCH A, B
OUT P0
JZ T
MOV A, 0
OUT P1
IN P1

s4SC-2 standard

T: MOV B, A
IN P0
JNZ T
XCH A, B
OUT P0
XCH A, B
CYCLES
472
at par
ENERGY
6486
at par
NODES
5
at par
INSTRUCTIONS
53
at par