14EDGE DETECTOR
The task
P must receive 1 when a value is 10 or more away from the one before it, else 0.
The value before the first is 0. MOV A, 1 puts a 1 in A.
The board
Key idea
Old and new value at one core, then a two sided test.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
The difference needs the new value and the old one at the same core.
Hint 2Show
XCH after IN keeps the new value in B and brings the old one into A.
Hint 3Show
A negative difference is as far as a positive one. JG, then NEG.
Solution
Reveal the Full SolutionThe complete program for EDGE DETECTOR. 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.
c0SC-2 standard
IN P0
OUT P1c2SC-2 standard
T: IN P0
XCH A, B
SUB B
JG G
NEG
G: SUB 10
JL N
MOV A, 1
OUT P2
JMP T
N: MOV A, 0
OUT P2- CYCLES
- 406
- at par
- ENERGY
- 2616
- at par
- NODES
- 2
- at par
- INSTRUCTIONS
- 14
- at par
Another way: Fork
A second program that also passes, by a different road, at a cost on CYCLES, ENERGY, NODES, and INSTRUCTIONS.
The fork: one path delays the stream by one, so old and new meet at the right core.
c0SC-2 standard
IN P0
OUT P1
OUT P2c1SC-2 standard
OUT P1
IN P0c2SC-2 standard
IN P0
MOV B, A
IN P1
SUB B
JG G
NEG
G: SUB 10
JL N
MOV A, 1
JMP O
N: MOV A, 0
O: OUT P2- CYCLES
- 446
- over par
- ENERGY
- 3558
- over par
- NODES
- 3
- over par
- INSTRUCTIONS
- 17
- over par