Syscall 2: Firmware, home

SignalChapter 11: Capstones

89SORTER

The task

X holds frames of 1 to 5 numbers from 1 to 99, and a 0 ends each frame.

P must receive each frame from smallest to largest, then its 0.

b and d are SC-2Ls, at 2 cycles a line for half energy. f is an SC-1, with only A.

The board

The board of SORTER6 cores: a, b, c, d, e, and f. Inputs X; outputs P.aSC-2 15 LINESbSC-2L 15 LINEScSC-2 15 LINESdSC-2L 15 LINESeSC-2 15 LINESfSC-1 3 LINESP0P1P0P1P0P1P0P1P0P1P0P1XP
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 sort as a pipeline: each pass holds back the largest so far, so frames of up to five need four passes.

Hints

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

Hint 1Show

One pass can hold back the largest number so far and send on the rest, then the largest.

Hint 2Show

After one such pass the largest is last. Each pass after it puts one more in place.

Hint 3Show

Five numbers need four passes, and there are five cores that can make one.

Solution

Reveal the Full SolutionThe complete program for SORTER. 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.

aSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

bSC-2L low power

IN P0
OUT P1

cSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

dSC-2L low power

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

eSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

fSC-1 lite

IN P0
OUT P1
CYCLES
741
at par
ENERGY
6806
at par
NODES
6
at par
INSTRUCTIONS
60
at par

Another way: Sorter relay on c

A second program that also passes. It beats par on ENERGY and gives some back on CYCLES.

Less energy than par, but slower. Both SC-2Ls make passes, and c relays.

aSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

bSC-2L low power

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

cSC-2 standard

IN P0
OUT P1

dSC-2L low power

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

eSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

fSC-1 lite

IN P0
OUT P1
CYCLES
760
over par
ENERGY
6132
under par
NODES
6
at par
INSTRUCTIONS
60
at par

Another way: Sorter relay on d

A second program that also passes. It beats par on CYCLES and gives some back on ENERGY.

Faster than par, at more energy. The second SC-2L, d, relays and b makes a pass, which keeps the slow pass at the front of the line.

aSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

bSC-2L low power

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

cSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

dSC-2L low power

IN P0
OUT P1

eSC-2 standard

L: IN P0
JZ F
SUB B
JG K
ADD B
O: OUT P1
JMP L
F: XCH A, B
OUT P1
MOV A, B
JMP O
K: ADD B
XCH A, B
JNZ O

fSC-1 lite

IN P0
OUT P1
CYCLES
710
under par
ENERGY
6838
over par
NODES
6
at par
INSTRUCTIONS
60
at par