S09OUT OF BREATH
The task
The breathing program, swapped about. Put it back.
Make CH1 breathe: a triangle from 0 up to 5 volts and back down, over and over.
Move the duty on P0 by 10 percent on each tick of P1, up to 100 and back down to 0.
The board
- Resistors
- R1 1 kΩ
- Capacitors
- C1 2.2 µF
- Probes
- CH1
Key idea
Par is 6 swaps. Core u1 needs 3 instruction swaps and 3 operand swaps. 5 of them trade two tiles that hold each other's places; look for those first, since one swap mends both.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Two loops: one climbs until the duty reaches 100, the other falls until it reaches 0.
Hint 2Show
B holds the duty between ticks.
Hint 3Show
JNZ falls through when A is 0, which ends the falling loop by itself.
Solution
Reveal the Full SolutionThe complete program for OUT OF BREATH. 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
UP: OUT P1
MOV A, B
SUB 10
MOV B, A
SUB P0
IN UP
JNZ 100
DN: IN P1
MOV A, 10
ADD B
MOV P0, A
OUT B
JNZ DN6 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
u1, swap the operandUPon line 6 with100on line 7. - In core
u1, swap the operand10on line 9 withBon line 10. - In core
u1, swap the operandP0on line 11 withBon line 12. - In core
u1, swap the instructionSUBon line 3 withADDon line 10. - In core
u1, swap the instructionOUTon line 1 withINon line 6. - In core
u1, swap the instructionSUBon line 5 withOUTon line 6.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
u1SC-2 standard
UP: IN P1
MOV A, B
ADD 10
MOV B, A
OUT P0
SUB 100
JNZ UP
DN: IN P1
MOV A, B
SUB 10
MOV B, A
OUT P0
JNZ DN- CYCLES
- 255
- at par
- ENERGY
- 510
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 13
- at par
- SWAPS
- 6
- at par
Another way: Swap b 10
A second program that also passes, by a different road, at a cost on SWAPS.
Another arrangement that passes, one swap from the reference.
u1SC-2 standard
UP: IN P1
MOV A, 10
ADD B
MOV B, A
OUT P0
SUB 100
JNZ UP
DN: IN P1
MOV A, B
SUB 10
MOV B, A
OUT P0
JNZ DN- CYCLES
- 255
- at par
- ENERGY
- 510
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 13
- at par
- SWAPS
- 7
- over par