Syscall 2: Firmware, home

SignalChapter 3: Chains and rings

19COMPARATOR

The task

X arrives in pairs. P must receive each pair with the smaller value first.

The stream forks into two paths that meet again at the core on the right.

The board

The board of COMPARATOR4 cores: c0, c1, c2, and c3. Inputs X; outputs P.c0SC-2 15 LINESc1SC-2 15 LINESc2SC-2 15 LINESc3SC-2 15 LINESP0P1P2P0P1P0P1P0P1P2XP
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

Order a pair: the min goes one way, the max the other, and they join.

Hints

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

Hint 1Show

One path can work out which value is bigger while the other carries the values.

Hint 2Show

MOV B, A then SUB B gives the second value minus the first.

Hint 3Show

To send the second value first, hold the first in B.

Solution

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

c0SC-2 standard

IN P0
OUT P1
OUT P2
IN P0
OUT P1
OUT P2

c1SC-2 standard

IN P0
MOV B, A
IN P0
SUB B
OUT P1

c2SC-2 standard

IN P0
OUT P1

c3SC-2 standard

T: IN P0
JL S
IN P1
OUT P2
IN P1
OUT P2
JMP T
S: IN P1
XCH A, B
IN P1
OUT P2
XCH A, B
OUT P2
CYCLES
274
at par
ENERGY
2558
at par
NODES
4
at par
INSTRUCTIONS
26
at par