Human Resource Machine/Year 23

Strategy
The first strategy that we're going to employ will be very straightforward. We're going to treat box 0 as the container for the smallest number. So we'll grab the first number and put it there, since we have nothing else to compare it with yet.

Next we'll grab the second number and place it in box 1. Then we'll compare the two by subtracting one from the other. If the number in box 0 is smaller, we'll leave it alone and get the next number. However, if the number in box 1 is smaller, we'll copy it over to box 0 before getting the next number. Every time we get the next number, we'll check if it's zero, and if it is, we'll copy the contents of box 0 to the OUTBOX and start over.

Optimizing for our usual "put the OUTBOX command above the first INBOX command, and JUMP over it the first time," your program should resemble the following:

JUMP    b a:    COPYFROM 0 OUTBOX b:   INBOX COPYTO  0 c: d:   INBOX JUMPZ   a    COPYTO   1 COPYFROM 0 SUB     1 JUMPN   d    COPYFROM 1 COPYTO  0 JUMP    c

Optimizing
There are a number of ways to optimize the above solution, and whittle away at the number of steps it takes to complete. However, if you truly want to achieve an optimized answer, you'll want to come up with a solution that uses nothing but box 0.

This means, after you grab a new number off the INBOX and do the subtraction, if you determine that the new number was smaller, you need to restore it. Fortunately, anything that you SUB from, you can also ADD to. So if you determine that the new number was smaller, you simply ADD the content of box 0 back to what the worker is holding, and place that in box 0. Otherwise you throw the difference away and move on to the next number.

With some clever uses of jumps (to hop over the ADD instruction when you don't want to use it), you can produce a single answer that meets both the size challenge as well as the speed challenge:

JUMP    b a:    COPYFROM 0 OUTBOX b:   INBOX JUMP    d c:    ADD      0 d:   COPYTO   0 e:   INBOX JUMPZ   a    SUB      0 JUMPN   c    JUMP     e