Syscall 2: Firmware, home

BenchChapter 8: Scarcity

B62ZONES

The task

P0 reads the input on CH1 as a percent of the supply.

Light exactly one LED: P1 below 30 percent, P2 from 30 to 69, P3 from 70 up.

Sample the input on each tick of P4.

The board

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

Key idea

Three zones of 40, 40, and the rest: adding 10 and dividing by 40 gives 0, 1, or 2.

Hints

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

Hint 1Show

With the zone in B: zone DIV 2 lights P3, zone MOD 2 lights P2.

Hint 2Show

P1 is lit only in zone 0: 2 minus the zone, divided by 2, is 1 there and 0 elsewhere.

Solution

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

The zone of the reading picks one of three LEDs.

u1SC-2 standard

IN P4
IN P0
ADD 10
DIV 40
MOV B, A
MOD 2
OUT P2
MOV A, B
DIV 2
OUT P3
MOV A, B
NEG
ADD 2
DIV 2
OUT P1
CYCLES
586
at par
ENERGY
1172
at par
NODES
1
at par
INSTRUCTIONS
15
at par