Syscall 2: Firmware, home

ShuffleChapter 10: Meshes

S40TIMESHARE

The task

Two streams share one wire, and every piece is out of place.

P must receive X plus Y, and Q X minus Y. Both reach dx on one wire.

The board

The board of TIMESHARE4 cores: mx, r1, r2, and dx. Inputs X and Y; outputs P and Q.mxSC-1 8 LINESr1SC-1 8 LINESr2SC-1 8 LINESdxSC-2 8 LINESP0P1P2P0P1P0P1P0P1P2XYPQ
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 7 swaps. Core mx needs 1 instruction swap and 1 operand swap; core dx needs 3 instruction swaps and 2 operand swaps. 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

mx sends Y first and X after it, so dx knows each value by its turn.

Hint 2Show

dx keeps the first value in B while it reads the second.

Hint 3Show

SUB B takes back an ADD B, so two of them after X plus Y leave X minus Y.

Solution

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

mxSC-1 lite

OUT P0
OUT P2
IN P1
IN P2

r1SC-1 lite

IN P0
OUT P1

r2SC-1 lite

IN P0
OUT P1

dxSC-2 standard

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

7 swaps back

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

  1. In core mx, swap the operand P0 on line 1 with P1 on line 3.
  2. In core mx, swap the instruction OUT on line 1 with IN on line 4.
  3. In core dx, swap the operand P2 on line 1 with P0 on line 8.
  4. In core dx, swap the operand B on line 5 with P1 on line 7.
  5. In core dx, swap the instruction ADD on line 1 with IN on line 4.
  6. In core dx, swap the instruction SUB on line 5 with OUT on line 6.
  7. In core dx, swap the instruction OUT on line 7 with SUB on line 8.

The finished program

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

mxSC-1 lite

IN P1
OUT P2
IN P0
OUT P2

r1SC-1 lite

IN P0
OUT P1

r2SC-1 lite

IN P0
OUT P1

dxSC-2 standard

IN P0
MOV B, A
IN P0
ADD B
OUT P1
SUB B
SUB B
OUT P2
CYCLES
436
at par
ENERGY
3276
at par
NODES
4
at par
INSTRUCTIONS
16
at par
SWAPS
7
at par