Syscall 2: Firmware, home

ShuffleChapter 3: Chains and rings

S02MIXED BAG

The task

A working program, swapped about. Put its pieces back where they belong.

P must receive the running total of X. A zero clears the total and sends 0.

The board

The board of MIXED BAG2 cores: c0 and c1. Inputs X; outputs P.c0SC-2 15 LINESc1SC-2 15 LINESP0P1P0P1XP
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 3 swaps. Core c1 needs 2 instruction swaps and 1 operand swap. 2 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

B keeps a value while A reads the next one.

Hint 2Show

ADD B then MOV B, A adds the value to the total and keeps the new total.

Hint 3Show

A line marked in red holds a piece that cannot go there, such as a label where a pin belongs.

Solution

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

c0SC-2 standard

IN P0
OUT P1

c1SC-2 standard

ADD P0
JZ N
OUT B
N: MOV B, P1
IN A

3 swaps back

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

  1. In core c1, swap the operand P1 on line 4 with A on line 5.
  2. In core c1, swap the instruction ADD on line 1 with IN on line 5.
  3. In core c1, swap the instruction OUT on line 3 with ADD on line 5.

The finished program

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

c0SC-2 standard

IN P0
OUT P1

c1SC-2 standard

IN P0
JZ N
ADD B
N: MOV B, A
OUT P1
CYCLES
230
at par
ENERGY
1590
at par
NODES
2
at par
INSTRUCTIONS
7
at par
SWAPS
3
at par