Syscall 2: Firmware, home

BenchChapter 6: Trees

B43THREE PHASE

The task

Three lamps share the ticks of P3. Each is dark one tick in three and lit the other two.

P0 is dark on ticks 3, 6, 9, and so on, P1 a tick before P0, and P2 a tick before P1.

The board

The chip of THREE PHASEChip u1 with 4 ports: P0 digital out, reaching R1, D1, CH1; P1 digital out, reaching R2, D2, CH2; P2 digital out, reaching R3, D3, CH3; P3 timer 20 cycles.u1CHIP SC-2P0DIGITAL OUTR1, D1, CH1P1DIGITAL OUTR2, D2, CH2P2DIGITAL OUTR3, D3, CH3P3TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Resistors
R1 330 Ω, R2 330 Ω, and R3 330 Ω
LEDs
D1 red, D2 yellow, and D3 blue
Probes
CH1, CH2, and CH3

Key idea

A lamp lights for any value but 0, so the count MOD 3 lights P0 on two ticks of three.

Hints

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

Hint 1Show

Adding 1 before the MOD moves the dark tick one place earlier.

Hint 2Show

Keep the running value in A: ADD 1, MOD 3, and OUT for each lamp in turn.

Solution

Reveal the Full SolutionThe complete program for THREE PHASE. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

Each lamp dark one tick in three, staggered.

u1SC-2 standard

IN P3
MOD 3
OUT P0
ADD 1
MOD 3
OUT P1
ADD 1
MOD 3
OUT P2
CYCLES
154
at par
ENERGY
308
at par
NODES
1
at par
INSTRUCTIONS
9
at par