Human Resource Machine/Year 25

Strategy
The goal here is very straightforward in concept, but takes a little planning to execute. We'll start by grabbing a number off the belt and making two copies of it. One will go in box 0, and that will be our countdown until we hit the number 0. The second copy will go in box 1, and that will be the accumulated sum of all the numbers.

Once we have these copies placed, we'll reduce the number in box 0 by one, and add that new number to box 1. We'll keep going like this until box 0 reaches zero, and then we'll copy the sum in box 1 to the outbox and start over.

There's just one edge case we need to look out for: what if the number on the IN conveyor is zero? In that case, we'll skip all of the math and transport it directly to the OUTBOX. As you can see, this solution makes no use of the 0 placed for you in box 5.

a:   INBOX JUMPZ   d    COPYTO   0 COPYTO  1 b:   BUMPDN   0 JUMPZ   c    ADD      1 COPYTO  1 JUMP    b c:    COPYFROM 1 d:   OUTBOX JUMP    a

Optimizing
The above solution precisely meets the size and speed challenge set by the level. However, it's possible to increase both the speed and the size.

Size
If we choose to ignore the impact to speed, we can reduce this program down to just ten instructions.

First, notice that we call COPYTO 1 twice; once before a jump label, and once before the JUMP command to that label. If we move the first COPYTO 1 below the label, we can eliminate the second COPYTO 1 command.

Second, if we perform the ADD after we bump the number down, we can change the completion test to a JUMP IF NEGATIVE and eliminate the concern for our edge case of receiving zero from the INBOX. If we do, it will decrease to -1 the first time around, and we'll quit before we add anything.

a:   INBOX COPYTO  0 b:   COPYTO   1 BUMPDN  0 JUMPN   c    ADD      1 JUMP    b c:    COPYFROM 1 OUTBOX JUMP    a

Speed
To speed the program up, we'll eliminate some unnecessary lines from the original program, and then we'll reorganize some of it to make it more efficient.

As explained above, we can eliminate the extra COPYTO 1 command by rearranging the jump label. Then we can move the OUTBOX command above the INBOX command, and we can also move the COPYFROM 1 command above the OUTBOX command, and jump over both of them the first time through.

JUMP    c a:    COPYFROM 1 b:   OUTBOX c:   INBOX JUMPZ   b    COPYTO   0 d:   COPYTO   1 BUMPDN  0 JUMPZ   a    ADD      1 JUMP    d