Syscall 2: Firmware, home

SignalChapter 11: Capstones

83CHECK DIGIT

The task

X is from 0 to 99. Double its ones digit; a 14 counts as 1 plus 4. Add the tens digit.

P must receive the digit that takes them plus the tens digit to a multiple of 10.

f is an SC-1, with no B, and g an SC-2L, at 2 cycles a line; both use half energy.

The board

The board of CHECK DIGIT4 cores: s, f, g, and m. Inputs X; outputs P.sSC-2 15 LINESfSC-1 8 LINESgSC-2L 15 LINESmSC-2 15 LINESP0P1P2P3P0P1P0P1P0P1P2P3XP
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

DIV and MOD split X into digits, two cheap cores double and fold one digit each, and a merger ends with MOD 10.

Hints

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

Hint 1Show

s can split X into digits: DIV 100 for the tens, DIV 10 then MOD 10 for the tens.

Hint 2Show

A doubled digit above 9 counts as it less 9. Any digit: 2 times it less 1, MOD 9, plus 1.

Hint 3Show

MUL, DIV, and MOD take f, the SC-1, 4 cycles each, where g, the SC-2L, takes 2 for any line.

Solution

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

sSC-2 standard

IN P0
OUT P1
OUT P3
DIV 10
MOD 10
OUT P2

fSC-1 lite

IN P0
DIV 100
ADD A
SUB 9
JG O
ADD 9
O: OUT P1

gSC-2L low power

IN P0
MOD 10
ADD A
SUB 9
JG O
ADD 9
O: OUT P1

mSC-2 standard

IN P1
MOV B, A
IN P0
ADD B
MOV B, A
IN P2
ADD B
NEG
ADD 30
MOD 10
OUT P3
CYCLES
561
at par
ENERGY
5558
at par
NODES
4
at par
INSTRUCTIONS
31
at par

Another way: Check digit ones on s

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

Faster than par, at more energy. s also takes the ones digit off X, so the slow SC-2L has one line less to run.

sSC-2 standard

IN P0
OUT P1
MOV B, A
MOD 10
OUT P3
MOV A, B
DIV 10
MOD 10
OUT P2

fSC-1 lite

IN P0
DIV 100
ADD A
SUB 9
JG O
ADD 9
O: OUT P1

gSC-2L low power

IN P0
ADD A
SUB 9
JG O
ADD 9
O: OUT P1

mSC-2 standard

IN P1
MOV B, A
IN P0
ADD B
MOV B, A
IN P2
ADD B
NEG
ADD 30
MOD 10
OUT P3
CYCLES
502
under par
ENERGY
6143
over par
NODES
4
at par
INSTRUCTIONS
33
over par

Another way: Check digit three

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

Three nodes and fewer instructions than par, but slower. s doubles the ones digit itself and sends m the tens digit added to it.

sSC-2 standard

IN P0
OUT P1
MOV B, A
DIV 10
MOD 10
XCH A, B
MOD 10
ADD A
SUB 9
JG O
ADD 9
O: ADD B
OUT P2

fSC-1 lite

IN P0
DIV 100
ADD A
SUB 9
JG O
ADD 9
O: OUT P1

mSC-2 standard

IN P0
MOV B, A
IN P1
ADD B
NEG
ADD 30
MOD 10
OUT P3
CYCLES
592
over par
ENERGY
5617
over par
NODES
3
under par
INSTRUCTIONS
28
under par