Syscall 2: Firmware, home

SignalChapter 11: Capstones

87ROOT

The task

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

a is an SC-4, with C and D as well. b is an SC-2D, where each jump takes 3 cycles.

c is an SC-2L: every instruction takes 2 cycles, for half the energy.

The board

The board of ROOT3 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

Newton in whole numbers: from a guess above the root, the average of the guess and X over it closes in, and the SC-4 keeps the guess in C.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

Take away 1, then 3, then 5, and so on: the count of odd numbers X has room for is its root.

Hint 2Show

From a guess above the root, the average of the guess and X divided by it is a closer guess.

Hint 3Show

A square past 121 wraps in this machine, so stay with X at or below 121.

Solution

Reveal the Full SolutionThe complete program for ROOT. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and 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
9240
at par
NODES
3
at par
INSTRUCTIONS
19
at par

Another way: Root odd numbers

A second program that also passes. It beats par on INSTRUCTIONS and gives some back on CYCLES and ENERGY.

Fewer instructions than par, but slower and more energy. a takes away 1, 3, 5, and so on until the next one no longer fits.

aSC-4 quad

S: MOV A, 1
MOV B, A
IN P0
L: SUB B
JL E
XCH A, B
ADD 2
XCH A, B
JMP L
E: MOV A, B
DIV 2
OUT P1

bSC-2D signal processor

IN P0
OUT P1

cSC-2L low power

IN P0
OUT P1
CYCLES
2024
over par
ENERGY
17118
over par
NODES
3
at par
INSTRUCTIONS
16
under par

Another way: Root pipeline

A second program that also passes. It beats par on ENERGY and gives some back on CYCLES and INSTRUCTIONS.

Faster and less energy than par, for more instructions. a guesses and takes one closer guess, b takes the next, and c keeps the smaller of that and one more.

aSC-4 quad

IN P0
MOV B, A
DIV 20
ADD 6
MOV C, A
MOV A, B
DIV C
ADD C
DIV 2
MOV C, A
MOV A, B
OUT P1
MOV A, C
OUT P1

bSC-2D signal processor

IN P0
MOV B, A
IN P0
XCH A, B
OUT P1
DIV B
ADD B
DIV 2
OUT P1

cSC-2L low power

IN P0
MOV B, A
IN P0
XCH A, B
DIV B
ADD B
DIV 2
SUB B
JL K
MOV A, 0
K: ADD B
OUT P1
CYCLES
1030
over par
ENERGY
8417
under par
NODES
3
at par
INSTRUCTIONS
35
over par