S33LONG WAY ROUND
The task
Three cores of a grid walker, each swapped about. Swaps stay inside a core.
X and Y are one point, and Z and W another. P must receive their distance on a grid.
That is the gap from X to Z plus the gap from Y to W, each counted as positive.
The board
Key idea
Par is 6 swaps. Core g1 needs 2 instruction swaps and 1 operand swap; core g2 needs 1 instruction swap; core t needs 1 instruction swap and 1 operand swap. 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
Each gap is a subtraction with its sign dropped.
Hint 2Show
JG skips the NEG when the gap is already positive.
Hint 3Show
t adds the two gaps where the branches meet.
Solution
Reveal the Full SolutionThe complete program for LONG WAY ROUND. 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.
g1SC-2 standard
JG B
MOV P1, A
IN P0
OUT B
IN K
NEG
K: SUB P2g2SC-2 standard
IN P1
MOV B, A
IN P0
SUB B
OUT K
NEG
K: JG P2tSC-2 standard
IN B
MOV P0, A
IN P1
OUT B
ADD P26 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
g1, swap the operandBon line 1 withP1on line 2. - In core
g1, swap the instructionJGon line 1 withINon line 5. - In core
g1, swap the instructionOUTon line 4 withSUBon line 7. - In core
g2, swap the instructionOUTon line 5 withJGon line 7. - In core
t, swap the operandBon line 1 withP0on line 2. - In core
t, swap the instructionOUTon line 4 withADDon line 5.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
g1SC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JG K
NEG
K: OUT P2g2SC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JG K
NEG
K: OUT P2tSC-2 standard
IN P0
MOV B, A
IN P1
ADD B
OUT P2- CYCLES
- 308
- at par
- ENERGY
- 4204
- at par
- NODES
- 3
- at par
- INSTRUCTIONS
- 19
- at par
- SWAPS
- 6
- at par