Syscall 2: Firmware, home

ShuffleChapter 7: Frames and loops

S23SPLIT DECISION

The task

The sign sorter, swapped about. Swap its pieces back.

Positive values from X go to P and negative ones to Q, in order. Zeros go nowhere.

The board

The board of SPLIT DECISION3 cores: h, c1, and c2. Inputs X; outputs P and Q.hSC-2 15 LINESc1SC-2 4 LINESc2SC-2 4 LINESP0P1P2P0P1P0P1XPQ
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

Par is 4 swaps. Core h needs 2 instruction swaps and 2 operand swaps. 2 of them trade two tiles that hold each other's places; look for those first, since one swap mends both.

Hints

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

Hint 1Show

JG jumps when A is above 0, and JL when it is below. A zero falls through both.

Hint 2Show

A value that falls through both jumps is dropped: back to the read.

Hint 3Show

Each leaf only passes values along: IN P0, then OUT P1.

Solution

Reveal the Full SolutionThe complete program for SPLIT DECISION. Open it only when you want the answer.

The board as dealt

This is the arrangement the game deals. Framed tiles are the ones out of place.

hSC-2 standard

T: IN P0
JMP N
JG T
JL T
G: OUT P1
JMP G
N: OUT P2

c1SC-2 standard

IN P0
OUT P1

c2SC-2 standard

IN P0
OUT P1

4 swaps back

Make these swaps in order. Lines are numbered from 1 in each core.

  1. In core h, swap the operand N on line 2 with G on line 6.
  2. In core h, swap the operand T on line 3 with N on line 6.
  3. In core h, swap the instruction JMP on line 2 with JG on line 3.
  4. In core h, swap the instruction JMP on line 3 with JL on line 4.

The finished program

Every tile back in place: the reference solution, which scores exactly par on every benchmark.

hSC-2 standard

T: IN P0
JG G
JL N
JMP T
G: OUT P1
JMP T
N: OUT P2

c1SC-2 standard

IN P0
OUT P1

c2SC-2 standard

IN P0
OUT P1
CYCLES
198
at par
ENERGY
1392
at par
NODES
3
at par
INSTRUCTIONS
11
at par
SWAPS
4
at par