82SIEVE
The task
X is from 2 to 120. P must receive only the primes: 2, 3, 5, 7, 11, 13, and so on.
b is an SC-2D: 10 lines, and every jump takes 3 cycles. Use DIV or MOD to test a divisor.
c is an SC-2L: every instruction takes 2 cycles, for half the energy.
The board
Key idea
A number up to 120 that is not prime has a divisor of 2, 3, 5, or 7, so a chain of MOD filters keeps the primes; which core tests which divisor sets the score.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
A number up to 120 that is not prime has a divisor of 2, 3, 5, or 7.
Hint 2Show
Each core can drop the numbers that one or two of those divide with MOD.
Hint 3Show
2, 3, 5, and 7 divide themselves, but they are prime, so let them through.
Solution
Reveal the Full SolutionThe complete program for SIEVE. 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.
aSC-2 standard
S: IN P0
MOV B, A
MOD 2
JNZ T1
MOV A, B
SUB 2
JG S
T1: MOV A, B
MOD 3
JNZ K
MOV A, B
SUB 3
JG S
K: MOV A, B
OUT P1bSC-2D signal processor
S: IN P0
MOV B, A
MOD 5
JNZ K
MOV A, B
SUB 5
JG S
K: MOV A, B
OUT P1cSC-2L low power
S: IN P0
MOV B, A
MOD 7
JNZ K
MOV A, B
SUB 7
JG S
K: MOV A, B
OUT P1- CYCLES
- 353
- at par
- ENERGY
- 2486
- at par
- NODES
- 3
- at par
- INSTRUCTIONS
- 33
- at par
Another way: Sieve relay
A second program that also passes. It beats par on ENERGY and INSTRUCTIONS and gives some back on CYCLES.
Less energy than par, but slower. The SC-2D only relays, and the low power SC-2L tests both 7 and 5.
aSC-2 standard
S: IN P0
MOV B, A
MOD 2
JNZ T1
MOV A, B
SUB 2
JG S
T1: MOV A, B
MOD 3
JNZ K
MOV A, B
SUB 3
JG S
K: MOV A, B
OUT P1bSC-2D signal processor
IN P0
OUT P1cSC-2L low power
S: IN P0
MOV B, A
MOD 7
JNZ T1
MOV A, B
SUB 7
JG S
T1: MOV A, B
MOD 5
JNZ K
MOV A, B
SUB 5
JG S
K: MOV A, B
OUT P1- CYCLES
- 392
- over par
- ENERGY
- 2296
- under par
- NODES
- 3
- at par
- INSTRUCTIONS
- 32
- under par
Another way: Sieve seven on b
A second program that also passes. It beats par on CYCLES and gives some back on ENERGY.
Faster than par, at more energy. b, the SC-2D, tests 7, and c, the SC-2L, tests 5.
aSC-2 standard
S: IN P0
MOV B, A
MOD 2
JNZ T1
MOV A, B
SUB 2
JG S
T1: MOV A, B
MOD 3
JNZ K
MOV A, B
SUB 3
JG S
K: MOV A, B
OUT P1bSC-2D signal processor
S: IN P0
MOV B, A
MOD 7
JNZ K
MOV A, B
SUB 7
JG S
K: MOV A, B
OUT P1cSC-2L low power
S: IN P0
MOV B, A
MOD 5
JNZ K
MOV A, B
SUB 5
JG S
K: MOV A, B
OUT P1- CYCLES
- 346
- under par
- ENERGY
- 2493
- over par
- NODES
- 3
- at par
- INSTRUCTIONS
- 33
- at par