S22LOSING STREAK
The task
The streak counter, swapped about. Swap its pieces back.
For each value, P must receive how many equal values in a row end with it.
The board
Key idea
Par is 4 swaps. Core c1 needs 1 operand swap; core c2 needs 1 instruction swap and 2 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
c1 sends each value minus the one before it, then keeps the value in B.
Hint 2Show
A difference of 0 means the streak goes on. Anything else starts it again at 1.
Hint 3Show
c2 keeps the count in B, and XCH brings it into A to add 1.
Solution
Reveal the Full SolutionThe complete program for LOSING STREAK. 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.
c0SC-2 standard
IN P0
OUT P1c1SC-2 standard
IN P0
SUB B
OUT P1
ADD A
MOV B, Bc2SC-2 standard
T: IN P0
JZ S
XCH A, A
MOV A, 1
JMP O
S: MOV B, B
ADD 1
MOV B, A
O: OUT P14 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
c1, swap the operandAon line 4 withBon line 5. - In core
c2, swap the operandAon line 3 with1on line 4. - In core
c2, swap the operandAon line 4 withBon line 6. - In core
c2, swap the instructionXCHon line 3 withMOVon line 6.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
c0SC-2 standard
IN P0
OUT P1c1SC-2 standard
IN P0
SUB B
OUT P1
ADD B
MOV B, Ac2SC-2 standard
T: IN P0
JZ S
MOV A, 1
MOV B, A
JMP O
S: XCH A, B
ADD 1
MOV B, A
O: OUT P1- CYCLES
- 279
- at par
- ENERGY
- 3042
- at par
- NODES
- 3
- at par
- INSTRUCTIONS
- 16
- at par
- SWAPS
- 4
- at par