Syscall 2: Firmware, home

ShuffleChapter 7: Frames and loops

S25OFFBEAT

The task

The quadrature blinker, swapped about. Swap it back.

Red on P0 and green on P1 each blink over four ticks of P2: on for two, off for two.

The green LED runs one tick behind the red one.

The board

The chip of OFFBEATChip 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. On a narrow screen, scroll the board sideways to see all of it.
Resistors
R1 330 Ω and R2 330 Ω
LEDs
D1 red and D2 green
Probes
CH1 and CH2

Key idea

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

IN P2 sleeps until the next tick and reads the count of ticks so far.

Hint 2Show

MOD 4 gives the phase, 0 to 3, and DIV 2 turns it into 0, 0, 1, 1.

Hint 3Show

ADD 3 before the MOD makes the second pattern one tick late.

Solution

Reveal the Full SolutionThe complete program for OFFBEAT. 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, A
OUT 4
DIV 2
DIV 3
MOV B, B
OUT P0
MOD 4
MOD 2
ADD P1

5 swaps back

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

  1. In core u1, swap the operand A on line 2 with B on line 6.
  2. In core u1, swap the operand 3 on line 5 with P0 on line 7.
  3. In core u1, swap the instruction OUT on line 7 with ADD on line 10.
  4. In core u1, swap the instruction OUT on line 3 with MOD on line 9.
  5. In core u1, swap the instruction DIV on line 5 with OUT on line 9.

The finished program

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

u1SC-2 standard

IN P2
MOV B, A
MOD 4
DIV 2
OUT P0
MOV A, B
ADD 3
MOD 4
DIV 2
OUT P1
CYCLES
231
at par
ENERGY
462
at par
NODES
1
at par
INSTRUCTIONS
10
at par
SWAPS
5
at par