46NEAREST
The task
P must receive 0 when Y is nearer to X than Z is, and 1 when Z is nearer.
On a tie, send 0.
The board
Key idea
Two distances from one shared value compared where the paths meet.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
A distance is a difference with its sign dropped.
Hint 2Show
Y and Z each need their own copy of X.
Hint 3Show
Compare the two distances where the paths meet.
Solution
Reveal the Full SolutionThe complete program for NEAREST. 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.
sSC-2 standard
IN P0
OUT P1
OUT P2lbSC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JG K
NEG
K: OUT P2lcSC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JL K
NEG
K: OUT P2jSC-2 standard
IN P0
MOV B, A
IN P1
ADD B
JG O
MOV A, 0
JMP F
O: MOV A, 1
F: OUT P2- CYCLES
- 341
- at par
- ENERGY
- 5496
- at par
- NODES
- 4
- at par
- INSTRUCTIONS
- 26
- at par
Another way: Both positive
A second program that also passes, by a different road, at a cost on CYCLES and ENERGY.
With both distances sent as positive and the judge subtracting them.
sSC-2 standard
IN P0
OUT P1
OUT P2lbSC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JG K
NEG
K: OUT P2lcSC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JG K
NEG
K: OUT P2jSC-2 standard
IN P1
MOV B, A
IN P0
SUB B
JG O
MOV A, 0
JMP F
O: MOV A, 1
F: OUT P2- CYCLES
- 459
- over par
- ENERGY
- 5504
- over par
- NODES
- 4
- at par
- INSTRUCTIONS
- 26
- at par