Syscall 2: Firmware, home

ShuffleChapter 9: Special nodes

S36BROKEN RECORD

The task

The run length encoder, swapped about. Swap its pieces back.

X is a stream of frames, each ended by a 0. Within a frame, a run is one value repeated.

For each run, P must receive the value and then how many times it came.

The board

The board of BROKEN RECORD2 cores: e and c. Inputs X; outputs P.eSC-4 15 LINEScSC-2 15 LINESP0P1P2P3P0P1XP
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 e needs 4 instruction swaps and 3 operand swaps. 6 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

B keeps the last value, so SUB B is 0 while the run goes on.

Hint 2Show

C keeps the count: MOV A, C, then ADD 1, then MOV C, A counts one more.

Hint 3Show

When the value changes, send the old value and its count, then start the count at 1.

Solution

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

eSC-4 quad

S: ADD C
JZ B
IN I
OUT B
XCH A, B
SUB F
OUT A
MOV P1, 1
ADD P1
F: MOV A, 1
MOV P0, A
JMP S
I: MOV A, C
JZ C
MOV C, A

cSC-2 standard

7 swaps back

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

  1. In core e, swap the operand C on line 1 with P0 on line 11.
  2. In core e, swap the operand A on line 7 with P1 on line 8.
  3. In core e, swap the operand 1 on line 8 with C on line 14.
  4. In core e, swap the instruction JZ on line 2 with SUB on line 6.
  5. In core e, swap the instruction OUT on line 4 with ADD on line 9.
  6. In core e, swap the instruction ADD on line 1 with IN on line 3.
  7. In core e, swap the instruction ADD on line 3 with JZ on line 14.

The finished program

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

eSC-4 quad

S: IN P0
SUB B
JZ I
ADD B
XCH A, B
JZ F
OUT P1
MOV A, C
OUT P1
F: MOV A, 1
MOV C, A
JMP S
I: MOV A, C
ADD 1
MOV C, A

cSC-2 standard

CYCLES
342
at par
ENERGY
2691
at par
NODES
1
at par
INSTRUCTIONS
15
at par
SWAPS
7
at par