S36BROKEN RECORD
The task
The run length encoder, swapped about. Swap its pieces back.
X is a stream of frames, each ended by a 0. Within a frame, a run is one value repeated.
For each run, P must receive the value and then how many times it came.
The board
Key idea
Par is 7 swaps. Core e needs 4 instruction swaps and 3 operand swaps. 6 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
B keeps the last value, so SUB B is 0 while the run goes on.
Hint 2Show
C keeps the count: MOV A, C, then ADD 1, then MOV C, A counts one more.
Hint 3Show
When the value changes, send the old value and its count, then start the count at 1.
Solution
Reveal the Full SolutionThe complete program for BROKEN RECORD. 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.
eSC-4 quad
S: ADD C
JZ B
IN I
OUT B
XCH A, B
SUB F
OUT A
MOV P1, 1
ADD P1
F: MOV A, 1
MOV P0, A
JMP S
I: MOV A, C
JZ C
MOV C, AcSC-2 standard
7 swaps back
Make these swaps in order. Lines are numbered from 1 in each core.
- In core
e, swap the operandCon line 1 withP0on line 11. - In core
e, swap the operandAon line 7 withP1on line 8. - In core
e, swap the operand1on line 8 withCon line 14. - In core
e, swap the instructionJZon line 2 withSUBon line 6. - In core
e, swap the instructionOUTon line 4 withADDon line 9. - In core
e, swap the instructionADDon line 1 withINon line 3. - In core
e, swap the instructionADDon line 3 withJZon line 14.
The finished program
Every tile back in place: the reference solution, which scores exactly par on every benchmark.
eSC-4 quad
S: IN P0
SUB B
JZ I
ADD B
XCH A, B
JZ F
OUT P1
MOV A, C
OUT P1
F: MOV A, 1
MOV C, A
JMP S
I: MOV A, C
ADD 1
MOV C, AcSC-2 standard
- CYCLES
- 342
- at par
- ENERGY
- 2691
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 15
- at par
- SWAPS
- 7
- at par