Syscall 2: Firmware, home

SignalChapter 12: Shared buses

95TAKE TURNS

The task

a, b, c, and d share a bus. X arrives at a, Y at b, and Z at c.

P, on d, must receive X plus Y plus Z.

The board

The board of TAKE TURNS4 cores: a, b, c, and d. Inputs X, Y, and Z; outputs P. 1 shared bus.aSC-2 15 LINESbSC-2 15 LINEScSC-2 3 LINESdSC-2 15 LINESP0P1P0P1P0P1P0P1XYZP
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

Three writers and one reader: the writers on the left must wait their turn, or the rounds mix.

Hints

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

Hint 1Show

When several cores have written, d takes a's value first, then b's, then c's.

Hint 2Show

But a can write its next X before d has read Z, and then a's goes first again.

Hint 3Show

Let a and b wait their turn after each value, until c's has gone.

Solution

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

IN P0
OUT P1
NOP
NOP
NOP

bSC-2 standard

IN P1
OUT P0
NOP

cSC-2 standard

IN P0
OUT P1

dSC-2 standard

IN P0
MOV B, A
IN P0
ADD B
MOV B, A
IN P0
ADD B
OUT P1
CYCLES
354
at par
ENERGY
4212
at par
NODES
4
at par
INSTRUCTIONS
18
at par