45LONGEST BRANCH
The task
X is the trunk, Y grows from X, and Z and W are two twigs on Y.
P must receive the largest sum along a path from X out to a twig.
The board
Key idea
Pick the larger twig where they meet, then add on the way down.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Every path takes X and Y, then one twig.
Hint 2Show
Pick the larger twig where they meet, then add on the way down.
Hint 3Show
Keep one twig in B while you compare, then add it back.
Solution
Reveal the Full SolutionThe complete program for LONGEST BRANCH. 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.
cSC-2 standard
IN P0
OUT P1dSC-2 standard
IN P0
OUT P1bSC-2 standard
IN P2
MOV B, A
IN P1
SUB B
JG K
MOV A, 0
K: ADD B
MOV B, A
IN P0
ADD B
OUT P3aSC-2 standard
IN P0
MOV B, A
IN P1
ADD B
OUT P2- CYCLES
- 454
- at par
- ENERGY
- 4552
- at par
- NODES
- 4
- at par
- INSTRUCTIONS
- 20
- at par