Syscall 2: Firmware, home

ShuffleChapter 8: Scarcity

S05SWITCHBACK

The task

Every piece of a working gate is here, out of place. Swap them back.

When Y is above 0, P must receive the next X. Otherwise Q must receive it.

The board

The board of SWITCHBACK1 core: g. Inputs X and Y; outputs P and Q.gSC-1 8 LINESP0P1P2P3XYPQ
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 g needs 2 instruction swaps and 2 operand swaps. 3 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

Read Y, jump on it, and only then read X. The jump remembers what Y said.

Hint 2Show

Every X goes somewhere, so both branches read it.

Hint 3Show

Instructions swap with instructions and operands with operands, inside one core.

Solution

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

gSC-1 lite

S: IN P1
OUT P2
IN P0
IN P3
JMP K
K: OUT P0
JG S

4 swaps back

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

  1. In core g, swap the operand P2 on line 2 with K on line 5.
  2. In core g, swap the operand P2 on line 5 with S on line 7.
  3. In core g, swap the instruction OUT on line 2 with JG on line 7.
  4. In core g, swap the instruction IN on line 4 with OUT on line 6.

The finished program

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

gSC-1 lite

S: IN P1
JG K
IN P0
OUT P3
JMP S
K: IN P0
OUT P2
CYCLES
219
at par
ENERGY
531
at par
NODES
1
at par
INSTRUCTIONS
7
at par
SWAPS
4
at par