Syscall 2: Firmware, home

SignalChapter 12: Shared buses

100LAST STOP

The task

X and Y are from 1 to 99. P over Q must be X over Y in lowest terms.

The upper bus joins a, b, and c, and the lower bus d, e, and f.

The board

The board of LAST STOP6 cores: a, b, c, d, e, and f. Inputs X and Y; outputs P and Q. 2 shared buses.aSC-2 15 LINESbSC-2 6 LINEScSC-2 15 LINESdSC-2 15 LINESeSC-2 15 LINESfSC-2 15 LINESP0P1P2P0P1P2P0P1P0P1P2P0P1P2P0P1XYPQ
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

Lowest terms over two buses: each divisor writer tells its feeder on a link when to send the next value.

Hints

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

Hint 1Show

Divide X and Y by the largest number that divides both; a loop of MOD B and XCH finds it.

Hint 2Show

c and f each need a value and that divisor, so a and d send theirs twice.

Hint 3Show

If a writes its next X before c has the divisor, c takes the X. b can tell a when to go.

Solution

Reveal the Full SolutionThe complete program for LAST STOP. 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-2 standard

IN P0
OUT P1
OUT P1
IN P2

bSC-2 standard

IN P0
OUT P1
IN P1
OUT P0
OUT P2

cSC-2 standard

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

dSC-2 standard

IN P0
OUT P1
OUT P1
IN P2

eSC-2 standard

IN P1
MOV B, A
IN P0
L: MOD B
JZ G
XCH A, B
JMP L
G: XCH A, B
OUT P0
OUT P1
OUT P2

fSC-2 standard

IN P0
MOV B, A
IN P0
XCH A, B
DIV B
OUT P1
CYCLES
1033
at par
ENERGY
10700
at par
NODES
6
at par
INSTRUCTIONS
36
at par