Syscall 2: Firmware, home

SignalChapter 6: Trees

47BUTTERFLY

The task

P must receive the largest of X, Y, Z, and W minus the smallest.

Each middle core can reach both of the cores on the right.

The board

The board of BUTTERFLY5 cores: f, nb, nd, rx, and ry. Inputs W, X, Y, and Z; outputs P.fSC-2 15 LINESnbSC-2 15 LINESndSC-2 15 LINESrxSC-2 15 LINESrySC-2 15 LINESP0P1P2P3P4P5P0P1P2P0P1P2P0P1P2P3P0P1P2XYZWP
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

Sort each pair, then send winners one way and losers the other on crossing wires; the low root hands its answer to the high one.

Hints

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

Hint 1Show

Sort each pair into its larger and smaller value.

Hint 2Show

The winners go one way and the losers the other.

Hint 3Show

One compare can give both answers if the first value stays in B.

Solution

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

fSC-2 standard

IN P0
OUT P4
IN P1
OUT P4
IN P2
OUT P5
IN P3
OUT P5

nbSC-2 standard

IN P0
MOV B, A
IN P0
SUB B
JG L
ADD B
XCH A, B
JMP O
L: ADD B
O: OUT P1
MOV A, B
OUT P2

ndSC-2 standard

IN P0
MOV B, A
IN P0
SUB B
JG L
ADD B
XCH A, B
JMP O
L: ADD B
O: OUT P1
MOV A, B
OUT P2

rxSC-2 standard

IN P0
MOV B, A
IN P1
SUB B
JG K
MOV A, 0
K: ADD B
MOV B, A
IN P2
NEG
ADD B
OUT P3

rySC-2 standard

IN P0
MOV B, A
IN P1
SUB B
JL K
MOV A, 0
K: ADD B
OUT P2
CYCLES
661
at par
ENERGY
11038
at par
NODES
5
at par
INSTRUCTIONS
52
at par