Syscall 2: Firmware, home

ShuffleChapter 8: Scarcity

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

The board of LOST COMBINATION3 cores: guess, judge, and vault. Locked: judge and vault. Inputs X; outputs P.guessSC-2 15 LINESjudgeLOCKEDT: IN P1MOV B, AIN P0SUB BJZ OJG HMOV A, -1JMP OH: MOV A, 1O: OUT P1OUT P0vaultLOCKEDS: IN P0L: OUT P1MOV B, AIN P1JZ SXCHJMP LP0P1P0P1P0P1XP
The board as the puzzle screen lays it out. Cyan pins read, lemon pins write, violet pins go both ways. On a narrow screen, scroll the board sideways to see all of it.

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 A

6 swaps back

Make these swaps in order. Lines are numbered from 1 in each core.

  1. In core guess, swap the operand P1 on line 4 with F on line 9.
  2. In core guess, swap the operand P1 on line 9 with A on line 13.
  3. In core guess, swap the instruction ADD on line 3 with IN on line 10.
  4. In core guess, swap the instruction SUB on line 4 with JZ on line 13.
  5. In core guess, swap the instruction OUT on line 7 with ADD on line 10.
  6. In core guess, swap the instruction OUT on line 10 with SUB on 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