S31LOST COMBINATION
The task
The safe cracker, swapped about. Swap its pieces back.
Send guesses to the judge. It answers -1 when a guess is low, 1 when high, and 0 when right.
P must receive each secret in turn. Secrets run from 0 to 99.
The board
Key idea
Par is 6 swaps. Core guess needs 4 instruction swaps and 2 operand swaps. 2 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
Keep the guess in B while A reads the answer.
Hint 2Show
Big steps up and single steps down will find any secret.
Hint 3Show
XCH brings the guess back into A before it changes or goes to P.
Solution
Reveal the Full SolutionThe complete program for LOST COMBINATION. 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.
guessSC-2 standard
G: OUT P0
MOV B, A
ADD P0
SUB P1
JG DN
XCH A, B
OUT 10
JMP G
DN: XCH F, B
IN 1
JMP G
F: XCH A, B
JZ A6 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
guess, swap the operandP1on line 4 withFon line 9. - In core
guess, swap the operandP1on line 9 withAon line 13. - In core
guess, swap the instructionADDon line 3 withINon line 10. - In core
guess, swap the instructionSUBon line 4 withJZon line 13. - In core
guess, swap the instructionOUTon line 7 withADDon line 10. - In core
guess, swap the instructionOUTon line 10 withSUBon line 13.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
guessSC-2 standard
G: OUT P0
MOV B, A
IN P0
JZ F
JG DN
XCH A, B
ADD 10
JMP G
DN: XCH A, B
SUB 1
JMP G
F: XCH A, B
OUT P1- CYCLES
- 13707
- at par
- ENERGY
- 41148
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 13
- at par
- SWAPS
- 6
- at par