Syscall 2: Firmware, home

ShuffleChapter 6: Trees

S21ROUGH EDGES

The task

The edge detector, swapped about. Swap its pieces back.

P must receive 1 when a value is 10 or more away from the one before it, else 0.

The value before the first is 0.

The board

The board of ROUGH EDGES3 cores: c0, c1, and c2. Inputs X; outputs P.c0SC-2 15 LINESc1SC-2 15 LINESc2SC-2 15 LINESP0P1P2P0P1P0P1P2XP
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 c2 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

XCH after IN keeps the new value in B and brings the old one into A.

Hint 2Show

JG skips the NEG when the difference is already positive.

Hint 3Show

After SUB 10, a negative result means the step was small: send 0.

Solution

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

c0SC-2 standard

IN P0
OUT P1

c1SC-2 standard

c2SC-2 standard

T: IN P0
XCH A, B
SUB 1
OUT P2
NEG
G: SUB 10
JG N
MOV A, B
OUT P2
JMP T
N: MOV A, 0
JL G

4 swaps back

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

  1. In core c2, swap the operand 1 on line 3 with B on line 8.
  2. In core c2, swap the operand P2 on line 4 with G on line 12.
  3. In core c2, swap the instruction OUT on line 4 with JG on line 7.
  4. In core c2, swap the instruction OUT on line 7 with JL on line 12.

The finished program

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

c0SC-2 standard

IN P0
OUT P1

c1SC-2 standard

c2SC-2 standard

T: IN P0
XCH A, B
SUB B
JG G
NEG
G: SUB 10
JL N
MOV A, 1
OUT P2
JMP T
N: MOV A, 0
OUT P2
CYCLES
401
at par
ENERGY
2606
at par
NODES
2
at par
INSTRUCTIONS
14
at par
SWAPS
4
at par