B05DIVIDER
The task
V1 sends a square wave into P0, a digital input.
IN P0 reads 1 while the input is high and 0 while it is low.
Toggle the LED on P1 at every rising edge of the input, so it blinks at half the rate.
The board
- Sources
- V1 5 V square at 250 Hz
- Resistors
- R1 330 Ω
- LEDs
- D1 green
- Probes
- CH1 and CH2
Key idea
A rising edge is a 1 read after a 0. Wait for the high, then wait for the low.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
1 minus the LED's last state is its next state. B can keep the state.
Hint 2Show
CH1 shows the input and CH2 the LED.
Solution
Reveal the Full SolutionThe complete program for DIVIDER. 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.
u1SC-2 standard
L: IN P0
JZ L
MOV A, 1
SUB B
MOV B, A
OUT P1
H: IN P0
JNZ H- CYCLES
- 400
- at par
- ENERGY
- 800
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 8
- at par
Another way: Xch
A second program that also passes, by a different road, at a cost on INSTRUCTIONS.
Keeps the state in B with XCH and flips it with NEG.
u1SC-2 standard
L: IN P0
JZ L
XCH A, B
NEG
ADD 1
OUT P1
XCH A, B
H: IN P0
JNZ H- CYCLES
- 400
- at par
- ENERGY
- 800
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 9
- over par