Syscall 2: Firmware, home

ShuffleChapter 8: Scarcity

S32TALL ORDER

The task

The order desk and the stock room, swapped about. Swaps stay inside a core.

Each value of Y is an order for that many values of X, from 1 to 3.

P must receive the sum of each order.

The board

The board of TALL ORDER2 cores: s and d. Inputs X and Y; outputs P.sSC-2 15 LINESdSC-2 5 LINESP0P1P0P1P2XYP
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 6 swaps. Core s needs 4 instruction swaps and 2 operand swaps. 4 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

The desk passes the count to the stock room and waits for the sum on the same wire.

Hint 2Show

JRX A jumps ahead A lines, into a run of jumps and reads.

Hint 3Show

A count of 3 falls past both jumps and reads three times.

Solution

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

sSC-2 standard

T: MOV A, 0
MOV B, A
JMP B
IN P0
IN A1
JRX A2
OUT P0
ADD B
MOV B, A
A2: IN P0
ADD B
MOV B, A
A1: IN A
ADD P1
JMP P1

dSC-2 standard

IN P0
OUT P1
IN P1
OUT P2

6 swaps back

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

  1. In core s, swap the operand B on line 3 with P1 on line 14.
  2. In core s, swap the operand P0 on line 4 with A on line 13.
  3. In core s, swap the instruction JMP on line 3 with IN on line 5.
  4. In core s, swap the instruction IN on line 4 with JRX on line 6.
  5. In core s, swap the instruction IN on line 6 with JMP on line 15.
  6. In core s, swap the instruction OUT on line 7 with IN on line 15.

The finished program

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

sSC-2 standard

T: MOV A, 0
MOV B, A
IN P1
JRX A
JMP A1
JMP A2
IN P0
ADD B
MOV B, A
A2: IN P0
ADD B
MOV B, A
A1: IN P0
ADD B
OUT P1

dSC-2 standard

IN P0
OUT P1
IN P1
OUT P2
CYCLES
271
at par
ENERGY
1654
at par
NODES
2
at par
INSTRUCTIONS
19
at par
SWAPS
6
at par