Human Resource Machine/Year 31

Strategy
To perform this task, you must grab every letter from the INBOX, and store the letters in different boxes. When you grab a 0, that's your cue to place the letters in the OUTBOX in the opposite order from how you collected them.

The best way to do this is to use a counter and bump that number up one at a time as you use it to indirectly place the letters in sequential boxes. Then when it's time to put them in the OUTBOX, you decrease the counter by one as you work your way backwards until you're back at the start.

The trick to this is that you'll need to bump the number up once before you even get started. You need to do this because you're not finished until you've copied the last letter (which was initially the first letter you collected), but then you need to reset the count before you start reversing a new string. However, with a slight tweak, this actually allows us to come in under the size requirement while still hitting the speed requirement.

a: b:   BUMPUP   14 INBOX JUMPZ   c    COPYTO   [14] JUMP    b c: d:    BUMPDN   14 JUMPZ   a    COPYFROM [14] OUTBOX JUMP    d

Optimizing
While the above solution already satisfies the speed and size requirement, we can improve the speed even more if we are willing to add one more instruction back in. Instead of preemptively bumping the counter up by one, we will start with box 0, and we'll even copy the contents in box 0 before we finish. We conclude each string by checking the value of box 14 before we bump it down.

a: b:   INBOX JUMPZ   c    COPYTO   [14] BUMPUP  14 JUMP    b c: d:    BUMPDN   14 COPYFROM [14] OUTBOX COPYFROM 14 JUMPZ   a    JUMP     d

This solution is a size optimization of the above solution, at the loss of speed (10/123 vs 11/118). This approach removes the need to copy from box 14 to do a zero check, instead doing a negative check right after the bumpdn. This means the cycle ends with a -1 value, so to reset it to zero we jump to the bumpup line instead of all the way to the beginning, removing the need to add another line to fix the number.

a:   INBOX JUMPZ   c    COPYTO   [14] b:   BUMPUP   14 JUMP    a c: d:    BUMPDN   14 JUMPN   b    COPYFROM [14] OUTBOX JUMP    d

This solution reads the contents of box 14 to see if it the counter has reached zero after writing each character to the outbox. We can instead test the counter immediately after bumping the value in box 14 down at the cost of two more instructions to special case writing out the last character. This improves the speed by saving one instruction for each iteration of the second loop.

JUMP    b a:    COPYFROM 0 OUTBOX b: c:   INBOX JUMPZ   d    COPYTO   [14] BUMPUP  14 JUMP    c d: e:    BUMPDN   14 JUMPZ   a    COPYFROM [14] OUTBOX JUMP    e