54RUN LENGTH
The task
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.
A run always ends where its frame does. e is an SC-4, with two more registers: C and D.
The board
Key idea
A run ends at a change or at the frame's 0, and a 0 inside the data is the end, not a value; the coder is an SC-4 that keeps the count in C.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Keep the last value in B so you can tell when the next one is different.
Hint 2Show
An SC-4 can keep the count itself: MOV C, A copies A into C, and c can sit idle.
Hint 3Show
A 0 from X is not a run, but it does end the one before it.
Solution
Reveal the Full SolutionThe complete program for RUN LENGTH. Open it only when you want the answer.
The reference program
The game's own solution. It passes every test and 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, A- CYCLES
- 342
- at par
- ENERGY
- 2691
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 15
- at par
Another way: Two cores
A second program that also passes, by a different road, at a cost on CYCLES, ENERGY, NODES, and INSTRUCTIONS.
The count on c, as before e was an SC-4: correct, but two cores spend more.
eSC-4 quad
S: IN P0
SUB B
JZ T
ADD B
XCH A, B
JZ T
OUT P1
MOV A, 0
OUT P2
IN P3
OUT P1
T: MOV A, B
JZ S
OUT P2cSC-2 standard
S: IN P0
JZ E
XCH A, B
ADD 1
MOV B, A
JMP S
E: XCH A, B
OUT P1- CYCLES
- 446
- over par
- ENERGY
- 4187
- over par
- NODES
- 2
- over par
- INSTRUCTIONS
- 22
- over par