Syscall 2: Firmware, home

ShuffleChapter 4: Stars and hubs

S10LOOSE CHANGE

The task

The meter driver, all of it here and none of it in place.

The locked meter adds each value it gets, writes its total to P, and sends the total back.

P must show the running total of X, back to 0 after each 0.

The board

The board of LOOSE CHANGE2 cores: feed and m. Locked: m. Inputs X; outputs P.feedSC-2 15 LINESmLOCKEDMOV B, AIN P0ADD BOUT P1OUT P0P0P1P0P1XP
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 feed needs 3 instruction swaps and 4 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

The meter can only add. To bring its total to 0, send the total with its sign flipped.

Hint 2Show

Keep the last total the meter sent back in B.

Hint 3Show

Read the meter answer before you send the next value.

Solution

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

feedSC-2 standard

T: OUT N
IN P1
JZ A
OUT B
MOV P1, A
JMP T
N: XCH P1, B
NEG
IN P0
IN P1

7 swaps back

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

  1. In core feed, swap the operand A on line 3 with P1 on line 7.
  2. In core feed, swap the operand B on line 4 with P1 on line 5.
  3. In core feed, swap the operand N on line 1 with P0 on line 9.
  4. In core feed, swap the operand P1 on line 2 with N on line 9.
  5. In core feed, swap the instruction OUT on line 1 with IN on line 9.
  6. In core feed, swap the instruction IN on line 2 with JZ on line 3.
  7. In core feed, swap the instruction IN on line 3 with OUT on line 4.

The finished program

Every tile back in place: the reference solution, which scores exactly par on every benchmark.

feedSC-2 standard

T: IN P0
JZ N
OUT P1
IN P1
MOV B, A
JMP T
N: XCH A, B
NEG
OUT P1
IN P1
CYCLES
426
at par
ENERGY
1386
at par
NODES
1
at par
INSTRUCTIONS
10
at par
SWAPS
7
at par

Another way: Swap a b

A second program that also passes, by a different road, at a cost on SWAPS.

Another arrangement that passes, one swap from the reference.

feedSC-2 standard

T: IN P0
JZ N
OUT P1
IN P1
MOV B, A
JMP T
N: XCH B, A
NEG
OUT P1
IN P1
CYCLES
426
at par
ENERGY
1386
at par
NODES
1
at par
INSTRUCTIONS
10
at par
SWAPS
8
over par