Syscall 2: Firmware, home

SignalChapter 6: Trees

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

The board of LONGEST BRANCH4 cores: a, b, c, and d. Inputs W, X, Y, and Z; outputs P.aSC-2 15 LINESbSC-2 15 LINEScSC-2 15 LINESdSC-2 15 LINESP0P1P2P0P1P2P3P0P1P0P1XYZWP
The board as the puzzle screen lays it out. Cyan pins read, lemon pins write, violet pins go both ways. On a narrow screen, scroll the board sideways to see all of it.

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 P1

dSC-2 standard

IN P0
OUT P1

bSC-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 P3

aSC-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