Syscall 2: Firmware, home

ShuffleChapter 7: Frames and loops

S26JUNK DRAWER

The task

The directory clerk's code, swapped about. Swap it back.

For each index 0 to 5 on X, P must receive that entry of the directory.

Entries 0 to 2 sit in the left drawer, 3 to 5 in the right. Each counts from 0.

The board

The board of JUNK DRAWER3 cores: d0, h, and d1. Locked: d0 and d1. Inputs X; outputs P.d0LOCKEDT: IN P0JZ NSUB 1JZ OMOV A, 101OUT P0JMP TN: MOV A, 104OUT P0JMP TO: MOV A, 50OUT P0hSC-2 15 LINESd1LOCKEDT: IN P0JZ NSUB 1JZ OMOV A, 102OUT P0JMP TN: MOV A, 120OUT P0JMP TO: MOV A, 118OUT P0P0P0P1P2P3P0XP
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 5 swaps. Core h needs 1 instruction swap and 4 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

SUB 3 tells the drawers apart: below 0 is the left drawer.

Hint 2Show

The right drawer's 0 is entry 3, so it gets the index less 3. ADD 3 undoes it for the left.

Hint 3Show

Ask a drawer, read its answer on the same pin, then send it to P.

Solution

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

hSC-2 standard

T: IN P2
SUB P1
OUT P3
OUT 3
IN P0
JL P3
JMP T
L: ADD 3
OUT P2
IN P1
OUT L

5 swaps back

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

  1. In core h, swap the operand P2 on line 1 with P0 on line 5.
  2. In core h, swap the operand P3 on line 3 with L on line 11.
  3. In core h, swap the operand P1 on line 2 with 3 on line 4.
  4. In core h, swap the operand P1 on line 4 with P2 on line 9.
  5. In core h, swap the instruction OUT on line 3 with JL on line 6.

The finished program

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

hSC-2 standard

T: IN P0
SUB 3
JL L
OUT P2
IN P2
OUT P3
JMP T
L: ADD 3
OUT P1
IN P1
OUT P3
CYCLES
519
at par
ENERGY
1636
at par
NODES
1
at par
INSTRUCTIONS
11
at par
SWAPS
5
at par