From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search

Instructions[edit]

Equalization Room

Get two things from the INBOX. If they are EQUAL, put ONE of them in the OUTBOX. Discard non-equal pairs. Repeat!

You got… COMMENTS! You can use them, if you like, to mark sections of your program.

Strategy[edit]

Clearly, comments are not a new command. They are simply a tool for you, as the author of a program, to help you keep portions of your program straight in your mind. Programmers use comments to help themselves and other programmers quickly identify what a potentially confusing section of code is trying to do.

In order to properly detect if two values are the same, there's a simple test we can perform. If we subtract two numbers, and the answer is zero, they must have been equal. Therefore, you can grab one number from the INBOX, store it somewhere, and then grab a second number and subtract it from the first. If the value is zero, we want to pick that number back up from the box and bring it to the OUTBOX. Otherwise, we ignore the unequal numbers and move on.

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

Optimizing[edit]

As with Year 9, your first solution may meet the size challenge, but it may fall slightly short of the speed challenge. So just like we did in Year 9, we can speed the program up by eliminating the jump between the OUTBOX instruction and the INBOX instruction. To do this, we move a few of the instructions to the top, and then jump over them for the very first execution of the program, like so:

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

Additional Optimization[edit]

We can speed up the program even further by eliminating the first jump and adding some redundancy.

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

Performance[edit]

Steps     Size      Speed
Goal        9         27
Reached    14         26