S07SPILLED BARS
The task
The bar graph program is here, swapped about. Swap it back.
Light an LED for each quarter of the supply the input on P0 reaches:
P1 from 25 percent, P2 from 50, and P3 from 75, sampled on each tick of P4.
The board
- 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 4 swaps. Core u1 needs 1 instruction swap and 3 operand swaps. Every one of them trades two tiles that hold each other's places, so each swap mends two.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
IN P0 reads the input as a percent of the 5 volt supply.
Hint 2Show
DIV 25 turns the reading into the number of quarters it has reached.
Hint 3Show
MOV A, B brings the reading back for the next LED.
Solution
Reveal the Full SolutionThe complete program for SPILLED BARS. 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 B
MOV P0, B
DIV 25
OUT A
MOV A, B
DIV 50
OUT P2
MOV P1, A
DIV 75
IN P34 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
u1, swap the operandBon line 2 withP0on line 3. - In core
u1, swap the operandBon line 3 withAon line 9. - In core
u1, swap the operandAon line 5 withP1on line 9. - In core
u1, swap the instructionOUTon line 1 withINon line 11.
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
MOV B, A
DIV 25
OUT P1
MOV A, B
DIV 50
OUT P2
MOV A, B
DIV 75
OUT P3- CYCLES
- 210
- at par
- ENERGY
- 420
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 11
- at par
- SWAPS
- 4
- at par