S49PECKING ORDER
The task
Three cores on a bus, their pieces swapped. Put each core back.
Y arrives at a and X at c. P, on b, must receive X minus Y.
The board
Key idea
Par is 9 swaps. Core a needs 1 instruction swap; core b needs 2 instruction swaps and 4 operand swaps; core c needs 1 instruction swap and 1 operand swap. 7 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
When a and c have both written, b's first IN takes a's value: it is farther left.
Hint 2Show
MOV B, A keeps the first value while b reads the second.
Hint 3Show
SUB B takes B from A, so the value read first is the one taken away.
Solution
Reveal the Full SolutionThe complete program for PECKING ORDER. 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.
aSC-2 standard
OUT P0
IN P1bSC-2 standard
SUB A
MOV P0, P1
OUT B
IN P0
IN BcSC-2 standard
OUT P1
IN P09 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
a, swap the instructionOUTon line 1 withINon line 2. - In core
b, swap the operandP0on line 2 withBon line 3. - In core
b, swap the operandAon line 1 withP0on line 4. - In core
b, swap the operandP1on line 2 withAon line 4. - In core
b, swap the operandP1on line 4 withBon line 5. - In core
b, swap the instructionSUBon line 1 withINon line 4. - In core
b, swap the instructionOUTon line 3 withINon line 5. - In core
c, swap the operandP1on line 1 withP0on line 2. - In core
c, swap the instructionOUTon line 1 withINon line 2.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
aSC-2 standard
IN P0
OUT P1bSC-2 standard
IN P0
MOV B, A
IN P0
SUB B
OUT P1cSC-2 standard
IN P0
OUT P1- CYCLES
- 237
- at par
- ENERGY
- 2106
- at par
- NODES
- 3
- at par
- INSTRUCTIONS
- 9
- at par
- SWAPS
- 9
- at par