Human Resource Machine/Year 12

Strategy
Just as with, the answer that will satisfy the optimization challenges does not involve adding a number with itself 39 times. In order to meet the requirement that the program be 14 commands or less, you'll need to think about the math a little bit, and other way you can reach a multiple of 40.

Optimizing
The thing to note about the number 40 is that it is the sum of two powers of two, 32 and 8. As you learned in, there are faster ways to multiply up to powers of two than brute-force adding a number to itself over and over.

To solve this, we're going to multiply the number by 32 the same way we multiplied it by 8, except that we will proceed to add the sums together two more times. You should also note that we calculate the value multiplied by eight in this process, so it's important to store that value so we can retrieve it for later use.

If you store all the values of your sums in new boxes, the boxes will contain the following values: After we add box 4 to itself to get the number times 32, we go back and add box 3 again to get (n × 32) + (n × 8), or simply n × 40.

a:   INBOX COPYTO  0 ADD     0 COPYTO  1 ADD     1 COPYTO  2 ADD     2 COPYTO  3 ADD     3 COPYTO  4 ADD     4 ADD     3 OUTBOX JUMP    a

Performance
Steps    Size      Speed Goal      14         56 Reached   14         56