Syscall 2: Firmware, home

ShuffleChapter 12: Shared buses

S48SQUARE ONE

The task

A square root, swapped about. Every piece is out of place.

X is from 0 to 121. P must receive its whole square root: 15 sends 3, and 16 sends 4.

The board

The board of SQUARE ONE3 cores: a, b, and c. Inputs X; outputs P.aSC-4 15 LINESbSC-2D 10 LINEScSC-2L 15 LINESP0P1P0P1P0P1XP
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 10 swaps. Core a needs 3 instruction swaps and 6 operand swaps; core b needs 1 instruction swap. 9 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

Start from a guess above the root: X divided by 20, plus 6.

Hint 2Show

The average of a guess and X divided by it is a closer guess.

Hint 3Show

Stop once a new guess is no smaller than the last, and send the last one.

Solution

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

aSC-4 quad

OUT A
MOV K, A
DIV P1
JMP 6
ADD 2
K: ADD C
L: MOV B, P0
MOV A, A
DIV C
DIV C
ADD L
SUB C
JL B
MOV C, C
IN 20

bSC-2D signal processor

OUT P0
IN P1

cSC-2L low power

IN P0
OUT P1

10 swaps back

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

  1. In core a, swap the operand A on line 1 with P0 on line 7.
  2. In core a, swap the operand K on line 2 with B on line 13.
  3. In core a, swap the operand P1 on line 3 with 20 on line 15.
  4. In core a, swap the operand 2 on line 5 with L on line 11.
  5. In core a, swap the operand B on line 7 with C on line 14.
  6. In core a, swap the operand A on line 8 with B on line 14.
  7. In core a, swap the instruction OUT on line 1 with IN on line 15.
  8. In core a, swap the instruction JMP on line 4 with ADD on line 5.
  9. In core a, swap the instruction DIV on line 10 with ADD on line 11.
  10. In core b, swap the instruction OUT on line 1 with IN on line 2.

The finished program

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

aSC-4 quad

IN P0
MOV B, A
DIV 20
ADD 6
JMP L
K: ADD C
L: MOV C, A
MOV A, B
DIV C
ADD C
DIV 2
SUB C
JL K
MOV A, C
OUT P1

bSC-2D signal processor

IN P0
OUT P1

cSC-2L low power

IN P0
OUT P1
CYCLES
999
at par
ENERGY
9024
at par
NODES
3
at par
INSTRUCTIONS
19
at par
SWAPS
10
at par