Syscall 2: Firmware, home

ShuffleChapter 7: Frames and loops

S08TANGLE

The task

A quad core program, out of order. More than one arrangement sums the window.

P must receive the sum of the last four X values, with zeros before the first one.

The board

The board of TANGLE1 core: win. Inputs X; outputs P.winSC-4 15 LINESP0P1XP
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 5 swaps. Core win needs 2 instruction swaps and 3 operand swaps. 4 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

Three swaps in a row move every value one register along, and A ends with the oldest.

Hint 2Show

ADD B, ADD C, and ADD D read the registers without changing them.

Hint 3Show

Any arrangement that passes the tests solves the puzzle, not only one.

Solution

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

winSC-4 quad

ADD P0
XCH A, D
XCH C, C
XCH A, P1
OUT B
IN A
ADD D
ADD B

5 swaps back

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

  1. In core win, swap the operand C on line 3 with A on line 6.
  2. In core win, swap the operand D on line 2 with B on line 8.
  3. In core win, swap the operand P1 on line 4 with D on line 8.
  4. In core win, swap the instruction ADD on line 1 with IN on line 6.
  5. In core win, swap the instruction OUT on line 5 with ADD on line 8.

The finished program

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

winSC-4 quad

IN P0
XCH A, B
XCH A, C
XCH A, D
ADD B
ADD C
ADD D
OUT P1
CYCLES
352
at par
ENERGY
2808
at par
NODES
1
at par
INSTRUCTIONS
8
at par
SWAPS
5
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.

winSC-4 quad

IN P0
XCH B, A
XCH A, C
XCH A, D
ADD B
ADD C
ADD D
OUT P1
CYCLES
352
at par
ENERGY
2808
at par
NODES
1
at par
INSTRUCTIONS
8
at par
SWAPS
6
over par