Syscall 2: Firmware, home

ShuffleChapter 8: Scarcity

S28SPOTLIGHT

The task

One LED at a time, and every piece of the program is out of place.

Sample P0 on each tick of P4 and light the one LED for the band it is in.

Green on P1 below 34 percent, yellow on P2 from 34, and red on P3 from 68.

The board

The chip of SPOTLIGHTChip u1 with 5 ports: P0 analog in, reaching V2, CH1; P1 digital out, reaching R1, D1, CH2; P2 digital out, reaching R2, D2, CH3; P3 digital out, reaching R3, D3, CH4; P4 timer 20 cycles.u1CHIP SC-2P0ANALOG INV2, CH1P1DIGITAL OUTR1, D1, CH2P2DIGITAL OUTR2, D2, CH3P3DIGITAL OUTR3, D3, CH4P4TIMER 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.
Sources
V1 2.5 V and V2 2.5 V triangle at 50 Hz
Resistors
R1 330 Ω, R2 330 Ω, and R3 330 Ω
LEDs
D1 green, D2 yellow, and D3 red
Probes
CH1, CH2, CH3, and CH4

Key idea

Par is 5 swaps. Core u1 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

DIV 34 turns the reading into its band: 0, 1, or 2.

Hint 2Show

MOD 2 is 1 only for the middle band, and DIV 2 is 1 only for the top one.

Hint 3Show

2 minus the band, divided by 2, is 1 only for the bottom band.

Solution

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

OUT P4
IN P0
DIV B
MOV B, A
IN 2
OUT P2
MOV 2, 2
DIV B
MOD P3
MOV A, A
SUB 34
DIV 2
OUT P1

5 swaps back

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

  1. In core u1, swap the operand B on line 3 with 34 on line 11.
  2. In core u1, swap the operand 2 on line 7 with A on line 10.
  3. In core u1, swap the operand 2 on line 7 with B on line 8.
  4. In core u1, swap the instruction OUT on line 1 with IN on line 5.
  5. In core u1, swap the instruction OUT on line 5 with MOD 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 P4
IN P0
DIV 34
MOV B, A
MOD 2
OUT P2
MOV A, B
DIV 2
OUT P3
MOV A, 2
SUB B
DIV 2
OUT P1
CYCLES
248
at par
ENERGY
496
at par
NODES
1
at par
INSTRUCTIONS
13
at par
SWAPS
5
at par