Syscall 2: Firmware, home

SignalChapter 7: Frames and loops

56CHECKSUM GATE

The task

X is a stream of frames, each ended by a 0. The first value is a check and the rest are data.

If the data add up to the check, P must receive the data and the 0. If not, the frame is lost.

Each frame holds 1 to 3 data values.

The board

The board of CHECKSUM GATE6 cores: m, q1, q2, q3, q4, and g. Inputs X; outputs P.mSC-2 15 LINESq1SC-2 4 LINESq2SC-2 4 LINESq3SC-2 15 LINESq4SC-2 15 LINESgSC-2 15 LINESP0P1P2P0P1P0P1P0P1P0P1P0P1P2XP
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

Check first, store the data in a line, then tell the gate to pass or drop it.

Hints

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

Hint 1Show

The answer is known only when the frame ends, so the data must wait in the line.

Hint 2Show

Take each data value away from the check as it passes. 0 left means the frame is good.

Hint 3Show

Tell g whether to pass or drop the frame before it starts reading the line.

Solution

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

mSC-2 standard

IN P0
NEG
MOV B, A
L: IN P0
OUT P1
JZ E
ADD B
MOV B, A
JMP L
E: ADD B
OUT P2

q1SC-2 standard

IN P0
OUT P1

q2SC-2 standard

IN P0
OUT P1

q3SC-2 standard

IN P0
OUT P1

q4SC-2 standard

IN P0
OUT P1

gSC-2 standard

S: IN P1
JZ K
DN: IN P0
JNZ DN
JMP S
K: IN P0
OUT P2
JNZ K
CYCLES
243
at par
ENERGY
2754
at par
NODES
6
at par
INSTRUCTIONS
27
at par