Syscall 2: Firmware, home

ShuffleChapter 6: Trees

S20HIGH TIDE

The task

Two copies of one core, each with its pieces swapped. Swaps stay inside a core.

P must receive the largest of each value from X and the two before it.

Count 0 before the start.

The board

The board of HIGH TIDE3 cores: c0, c1, and c2. Inputs X; outputs P.c0SC-2 15 LINESc1SC-2 15 LINESc2SC-2 15 LINESP0P1P0P1P0P1XP
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 4 swaps. Core c1 needs 1 instruction swap and 1 operand swap; core c2 needs 1 instruction swap and 1 operand swap. Every one of them trades two tiles that hold each other's places, so each swap mends two.

Hints

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

Hint 1Show

Each core sends the larger of a value and the one before it. Two in a row make three.

Hint 2Show

XCH keeps the new value in B and brings the old one into A.

Hint 3Show

After SUB B, a gap of 0 or less means the new value wins: clear A, and ADD B brings it back.

Solution

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

IN P0
XCH A, B
ADD B
JG K
MOV B, 0
K: SUB A
OUT P1

c2SC-2 standard

IN P0
XCH A, B
SUB B
JG K
MOV A, 0
K: OUT P1
ADD B

4 swaps back

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

  1. In core c1, swap the operand B on line 5 with A on line 6.
  2. In core c1, swap the instruction ADD on line 3 with SUB on line 6.
  3. In core c2, swap the operand P1 on line 6 with B on line 7.
  4. In core c2, swap the instruction OUT on line 6 with ADD on line 7.

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
XCH A, B
SUB B
JG K
MOV A, 0
K: ADD B
OUT P1

c2SC-2 standard

IN P0
XCH A, B
SUB B
JG K
MOV A, 0
K: ADD B
OUT P1
CYCLES
319
at par
ENERGY
3542
at par
NODES
3
at par
INSTRUCTIONS
16
at par
SWAPS
4
at par