S29PHOTO FINISH
The task
The race judge, swapped about. Swaps stay inside a core.
P must receive which of X, Y, and Z is largest: 0, 1, or 2.
On a tie the earlier stream wins.
The board
Key idea
Par is 6 swaps. Core c1 needs 3 instruction swaps and 1 operand swap; core c2 needs 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 compares X with Y and sends the leader's value, then its number.
Hint 2Show
After SUB B, ADD B gives the value in A back.
Hint 3Show
c2 compares the leader with Z. Only a larger Z wins, so that takes a JG.
Solution
Reveal the Full SolutionThe complete program for PHOTO FINISH. 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.
sbSC-2 standard
IN P0
OUT P1c1SC-2 standard
OUT P1
MOV A, A
JMP P0
OUT B
JL H
ADD B
SUB P2
MOV A, 0
IN O
H: MOV A, B
OUT P2
MOV B, 1
O: IN P2c2SC-2 standard
T: IN P0
MOV B, P2
IN A
SUB B
JG H
IN P0
JMP O
H: IN P0
MOV P1, 2
O: OUT A6 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
c1, swap the operandAon line 2 withBon line 12. - In core
c1, swap the instructionOUTon line 1 withINon line 13. - In core
c1, swap the instructionJMPon line 3 withINon line 9. - In core
c1, swap the instructionOUTon line 4 withSUBon line 7. - In core
c2, swap the operandP2on line 2 withAon line 10. - In core
c2, swap the operandAon line 3 withP1on line 9.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
sbSC-2 standard
IN P0
OUT P1c1SC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JL H
ADD B
OUT P2
MOV A, 0
JMP O
H: MOV A, B
OUT P2
MOV A, 1
O: OUT P2c2SC-2 standard
T: IN P0
MOV B, A
IN P1
SUB B
JG H
IN P0
JMP O
H: IN P0
MOV A, 2
O: OUT P2- CYCLES
- 513
- at par
- ENERGY
- 4566
- at par
- NODES
- 3
- at par
- INSTRUCTIONS
- 25
- at par
- SWAPS
- 6
- at par