Syscall 2: Firmware, home

ShuffleChapter 9: Special nodes

S35HAREBRAINED

The task

The rabbit counter, swapped about. Swaps stay inside a core.

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 HAREBRAINED2 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

Par is 7 swaps. Core f needs 2 instruction swaps and 5 operand swaps. 5 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

f keeps the count in B and the number in A, and XCH trades them.

Hint 2Show

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

Hint 3Show

f sends g a 0 first, so g starts each X from nothing.

Solution

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

fSC-2 standard

IN P0
SUB 1
MOV 1, A
IN B
OUT DN
MOV A, B
L: XCH A, B
SUB B
JZ 1
XCH L, P2
OUT P2
SUB A
JMP P3
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

7 swaps back

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

  1. In core f, swap the operand 1 on line 3 with B on line 6.
  2. In core f, swap the operand DN on line 5 with P2 on line 10.
  3. In core f, swap the operand B on line 8 with DN on line 10.
  4. In core f, swap the operand L on line 10 with A on line 12.
  5. In core f, swap the operand L on line 12 with P3 on line 13.
  6. In core f, swap the instruction IN on line 4 with SUB on line 12.
  7. In core f, swap the instruction SUB on line 8 with JZ on line 9.

The finished program

Every tile back in place: the reference solution, which 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
SWAPS
7
at par