Syscall 2: Firmware, home

ShuffleChapter 9: Special nodes

S33LONG WAY ROUND

The task

Three cores of a grid walker, each swapped about. Swaps stay inside a core.

X and Y are one point, and Z and W another. P must receive their distance on a grid.

That is the gap from X to Z plus the gap from Y to W, each counted as positive.

The board

The board of LONG WAY ROUND3 cores: g1, g2, and t. Inputs W, X, Y, and Z; outputs P.g1SC-2 15 LINESg2SC-2 15 LINEStSC-2 6 LINESP0P1P2P0P1P2P0P1P2XZYWP
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 6 swaps. Core g1 needs 2 instruction swaps and 1 operand swap; core g2 needs 1 instruction swap; core t needs 1 instruction swap and 1 operand swap. Every one of them trades two tiles that hold each other's places, so each swap mends two.

Hints

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

Hint 1Show

Each gap is a subtraction with its sign dropped.

Hint 2Show

JG skips the NEG when the gap is already positive.

Hint 3Show

t adds the two gaps where the branches meet.

Solution

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

g1SC-2 standard

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

g2SC-2 standard

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

tSC-2 standard

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

6 swaps back

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

  1. In core g1, swap the operand B on line 1 with P1 on line 2.
  2. In core g1, swap the instruction JG on line 1 with IN on line 5.
  3. In core g1, swap the instruction OUT on line 4 with SUB on line 7.
  4. In core g2, swap the instruction OUT on line 5 with JG on line 7.
  5. In core t, swap the operand B on line 1 with P0 on line 2.
  6. In core t, swap the instruction OUT on line 4 with ADD on line 5.

The finished program

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

g1SC-2 standard

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

g2SC-2 standard

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

tSC-2 standard

IN P0
MOV B, A
IN P1
ADD B
OUT P2
CYCLES
308
at par
ENERGY
4204
at par
NODES
3
at par
INSTRUCTIONS
19
at par
SWAPS
6
at par