86HAILSTONE
The task
A step halves an even number and takes an odd one to 3 times it plus 1.
X is from 1 to 28 and never climbs past 127. P must receive the steps X takes to reach 1.
t is an SC-2L: every instruction takes 2 cycles, for half the energy.
The board
Key idea
A counter and a stepper on a loop; MOD 2 picks the step, and MUL 3 then ADD 1 on an odd number never passes 999.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
t can keep the count in B and send each number round to c for its next step.
Hint 2Show
MOD 2 leaves 0 for an even number. Keep the number in B so the step can still use it.
Hint 3Show
Look for 1 before each step, so that 1 itself takes none.
Solution
Reveal the Full SolutionThe complete program for HAILSTONE. 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.
tSC-2L low power
S: IN P0
L: SUB 1
JZ F
ADD 1
OUT P1
XCH A, B
ADD 1
MOV B, A
IN P2
JMP L
F: XCH A, B
OUT P3cSC-2 standard
S: IN P0
MOV B, A
MOD 2
JZ E
MOV A, B
MUL 3
ADD 1
OUT P1
JMP S
E: MOV A, B
DIV 2
OUT P1- CYCLES
- 3178
- at par
- ENERGY
- 10528
- at par
- NODES
- 2
- at par
- INSTRUCTIONS
- 24
- at par
Another way: Hailstone c loops
A second program that also passes. It beats par on CYCLES and gives some back on ENERGY and INSTRUCTIONS.
Faster than par, at more energy. c runs the whole path and sends each number less 1; the low power t only counts until a 0 comes back.
tSC-2L low power
S: IN P0
OUT P1
K: IN P2
JZ F
XCH A, B
ADD 1
XCH A, B
JMP K
F: XCH A, B
OUT P3cSC-2 standard
S: IN P0
L: SUB 1
OUT P1
JZ S
ADD 1
MOV B, A
MOD 2
JZ E
MOV A, B
MUL 3
ADD 1
JMP L
E: MOV A, B
DIV 2
JMP L- CYCLES
- 2136
- under par
- ENERGY
- 12022
- over par
- NODES
- 2
- at par
- INSTRUCTIONS
- 25
- over par