Syscall 2: Firmware, home

SignalChapter 6: Trees

43HEADCOUNT

The task

P must receive how many of Y, Z, and W are less than X.

The core with X reaches each of the others on its own wire.

The board

The board of HEADCOUNT4 cores: h, lb, lc, and ld. Inputs W, X, Y, and Z; outputs P.hSC-2 15 LINESlbSC-2 15 LINESlcSC-2 15 LINESldSC-2 15 LINESP0P1P2P3P4P0P1P0P1P0P1XYZWP
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

Broadcast one value on three bi wires and add the answers.

Hints

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

Hint 1Show

Send X out to each core, then read three answers.

Hint 2Show

An answer of 1 or 0 can just be added up.

Hint 3Show

A tie is not less.

Solution

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

IN P0
OUT P1
OUT P2
OUT P3
IN P1
MOV B, A
IN P2
ADD B
MOV B, A
IN P3
ADD B
OUT P4

lbSC-2 standard

IN P1
MOV B, A
IN P0
SUB B
JL L
MOV A, 0
JMP O
L: MOV A, 1
O: OUT P1

lcSC-2 standard

IN P1
MOV B, A
IN P0
SUB B
JL L
MOV A, 0
JMP O
L: MOV A, 1
O: OUT P1

ldSC-2 standard

IN P1
MOV B, A
IN P0
SUB B
JL L
MOV A, 0
JMP O
L: MOV A, 1
O: OUT P1
CYCLES
730
at par
ENERGY
8048
at par
NODES
4
at par
INSTRUCTIONS
39
at par