Syscall 2: Firmware, home

SignalChapter 7: Frames and loops

52RABBITS

The task

P must receive Fibonacci number X, where X is from 1 to 11.

The numbers go 1, 1, 2, 3, 5, 8 and so on, each the sum of the two before it.

The board

The board of RABBITS2 cores: f and g. Inputs X; outputs P.fSC-2 15 LINESgSC-2 15 LINESP0P1P2P3P0P1XP
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

Two numbers of state and a count: the pair lives in a helper and the count in the worker.

Hints

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

Hint 1Show

f cannot hold the count and two numbers at once, but g can keep one of them.

Hint 2Show

If g keeps the last number it saw in B, XCH then ADD B gives it the next one.

Hint 3Show

Send g a 0 first so it starts each X from nothing.

Solution

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

fSC-2 standard

IN P0
SUB 1
MOV B, A
SUB B
OUT P2
MOV A, 1
L: XCH A, B
JZ DN
SUB 1
XCH A, B
OUT P2
IN P3
JMP L
DN: XCH A, B
OUT P1

gSC-2 standard

S: IN P0
JZ R
XCH A, B
ADD B
OUT P1
JMP S
R: MOV B, A
CYCLES
925
at par
ENERGY
5772
at par
NODES
2
at par
INSTRUCTIONS
22
at par

Another way: Reset reply

A second program that also passes, by a different road, at a cost on CYCLES and ENERGY.

G answers the 0 with the first number, which leaves f two spare lines.

fSC-2 standard

IN P0
SUB 1
MOV B, A
SUB B
L: OUT P2
IN P3
XCH A, B
JZ DN
SUB 1
XCH A, B
JMP L
DN: XCH A, B
OUT P1

gSC-2 standard

S: IN P0
JZ R
XCH A, B
ADD B
OUT P1
JMP S
R: MOV B, A
MOV A, 1
OUT P1
CYCLES
973
over par
ENERGY
5916
over par
NODES
2
at par
INSTRUCTIONS
22
at par