Syscall 2: Firmware, home

ShuffleChapter 6: Trees

S18SEESAW

The task

The railroad lamps, their code swapped about. Swap it back.

Trade the lamps on each tick of P2: red on P0 lit and amber on P1 dark, then the reverse.

The board

The chip of SEESAWChip u1 with 3 ports: P0 digital out, reaching R1, D1, CH1; P1 digital out, reaching R2, D2, CH2; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL OUTR1, D1, CH1P1DIGITAL OUTR2, D2, CH2P2TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Resistors
R1 330 Ω and R2 330 Ω
LEDs
D1 red and D2 yellow
Probes
CH1 and CH2

Key idea

Par is 3 swaps. Core u1 needs 1 instruction swap and 2 operand swaps. 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

A digital output stays where you left it until the next OUT on that pin.

Hint 2Show

Light one lamp and put the other out before you sleep again.

Hint 3Show

Each MOV sets the value that the OUT after it writes.

Solution

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

u1SC-2 standard

IN P2
MOV A, 1
OUT P1
MOV A, 0
IN P2
OUT P0
MOV A, 0
OUT P0
MOV A, 1
OUT P1

3 swaps back

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

  1. In core u1, swap the operand P1 on line 3 with P0 on line 6.
  2. In core u1, swap the operand P2 on line 5 with P1 on line 6.
  3. In core u1, swap the instruction IN on line 5 with OUT on line 6.

The finished program

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

u1SC-2 standard

IN P2
MOV A, 1
OUT P0
MOV A, 0
OUT P1
IN P2
MOV A, 0
OUT P0
MOV A, 1
OUT P1
CYCLES
46
at par
ENERGY
92
at par
NODES
1
at par
INSTRUCTIONS
10
at par
SWAPS
3
at par