Human Resource Machine/Year 17

Strategy
For the first time in a while, the boxes on the floor come pre-loaded with a set of values. There's a 0 in box 4 and a 1 in box 5. You'll be using those as the values that you'll ultimately place in the OUTBOX. So to start, let's just setup the OUTBOX portion of the code. We'll set up something like this:

JUMP    b    COPYFROM 4 JUMP    a    COPYFROM 5 a:   OUTBOX b:   INBOX

Now when you detect two numbers that are the same, you'll jump up above the COPYFROM 4, and when you detect two numbers that are different, you'll jump up above the COPYFROM 5.

For the rest of the program, you'll want to create a branching path that resembles the following decision tree:

Turning that into a program looks like so:

JUMP    f a: b:    COPYFROM 4 JUMP    e c: d:    COPYFROM 5 e:   OUTBOX f:   INBOX JUMPN   g    INBOX JUMPN   c    JUMP     b g:    INBOX JUMPN   a    JUMP     d

Optimizing Size
The above solution is pretty well optimized, and it will meet the speed challenge of the level, but it won't meet the size challenge. Intuitively carving an instruction out of the above program is not easy. It may feel as though everything that's there needs to be there in order for the program to work, so how can you remove anything?

The trick here again is to cut back on the number of jumps you need to make. In particular, the jump up to COPYFROM 4 and then another jump down to OUTBOX is slightly inefficient (although not incredibly so.) Never the less, it is possible to rearrange some of the instructions so that you can remove at least one JUMP command.

To do this, we'll bring the COPYFROM 4 instruction down from the top and drop it in below the second JUMP IF NEGATIVE. From there, we'll jump back to the OUTBOX. Likewise, move the third JUMP IF NEGATIVE to just above the newly moved COPYFROM 4. Now you can eliminate the JUMP that used to be below the COPYFROM 4 when it was at the top. Your new solution will look like so:

JUMP    d a: b:    COPYFROM 5 c:   OUTBOX d:   INBOX JUMPN   f    INBOX JUMPN   a e:    COPYFROM 4 JUMP    c f:    INBOX JUMPN   e    JUMP     b

Additional Optimization (Speed)
We can speed up the program even further by eliminating the first jump and adding some redundant code.

INBOX JUMPN   d    INBOX JUMPN   b  a:    COPYFROM 4 JUMP    g b: c:    COPYFROM 5 JUMP    h d: e:    INBOX JUMPN   f    COPYFROM 5 JUMP    i f:    COPYFROM 4 g: h: i:   OUTBOX INBOX JUMPN   c    JUMP     a

Performance
Steps    Size      Speed Goal      12         28 Reached   12         27