Syscall 2: Firmware, home

ShuffleChapter 5: Half duplex

S13BOTH HANDS

The task

The lines are shuffled. Swap them back into an order that runs.

P must receive X and Y added together. XCH A, B trades the two registers.

The board

The board of BOTH HANDS1 core: a. Inputs X and Y; outputs P.aSC-2 15 LINESP0P1P2XYP
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 3 swaps. Core a needs 2 instruction swaps 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

XCH A, B swaps A and B. Both names are required.

Hint 2Show

Read X, park it with XCH A, B, read Y, then ADD B.

Hint 3Show

OUT is last. It sends whatever A holds at that moment.

Solution

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

aSC-2 standard

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

3 swaps back

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

  1. In core a, swap the operand B on line 1 with P0 on line 2.
  2. In core a, swap the instruction ADD on line 1 with IN on line 4.
  3. In core a, swap the instruction OUT on line 3 with IN on line 5.

The finished program

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

aSC-2 standard

IN P0
XCH A, B
IN P1
ADD B
OUT P2
CYCLES
235
at par
ENERGY
1170
at par
NODES
1
at par
INSTRUCTIONS
5
at par
SWAPS
3
at par