29MEDIAN
The task
P must receive the middle value of X, Y, and Z each time.
Four cores, with one wire between each pair.
The board
Key idea
A comparator chain: sort two, raise the third to the low, lower it to the high.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Sort X and Y into a low and a high first.
Hint 2Show
The median is Z held between the low and the high.
Hint 3Show
Raise Z to at least the low, then lower it to at most the high.
Solution
Reveal the Full SolutionThe complete program for MEDIAN. 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.
kSC-2 standard
IN P2
MOV B, A
IN P0
SUB B
JL H
ADD B
XCH A, B
JMP O
H: ADD B
O: OUT P1
MOV A, B
OUT P1mSC-2 standard
IN P0
MOV B, A
IN P1
SUB B
JG K
MOV A, 0
K: ADD B
OUT P2
IN P0
OUT P2sSC-2 standard
IN P0
OUT P1fSC-2 standard
IN P0
MOV B, A
IN P0
SUB B
JL K
MOV A, 0
K: ADD B
OUT P1- CYCLES
- 701
- at par
- ENERGY
- 6826
- at par
- NODES
- 4
- at par
- INSTRUCTIONS
- 32
- at par