B42COUNTER
The task
Three LEDs count the ticks of P3 in binary: P0 is the ones bit, P1 the twos, P2 the fours.
Show the count of ticks so far, and start over at 0 after 7.
The board
- Resistors
- R1 330 Ω, R2 330 Ω, and R3 330 Ω
- LEDs
- D1 green, D2 yellow, and D3 red
- Probes
- CH1, CH2, and CH3
Key idea
IN P3 gives the number of ticks so far.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
MOD 2 of a number is its ones bit. Divide by 2 first for the twos bit, by 4 for the fours.
Hint 2Show
Keep the count in B and bring it back for each bit.
Solution
Reveal the Full SolutionThe complete program for COUNTER. 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.
Three LEDs count the ticks in binary.
u1SC-2 standard
IN P3
MOV B, A
MOD 2
OUT P0
MOV A, B
DIV 2
MOD 2
OUT P1
MOV A, B
DIV 4
MOD 2
OUT P2- CYCLES
- 277
- at par
- ENERGY
- 554
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 12
- at par