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

Instructions[edit]

Small Divide

For each two things in the INBOX, how many times does the second fully fit into the first? Don't worry about negative numbers, divide by zero, or remainders.

Self improvement tip: This might be a good time to practice copying and pasting from a previous assignment!

Strategy[edit]

Whether you choose to follow the game's advice and copy your answer from Year 24 or not is entirely up to you.

We'll follow the same basic principal established in Year 24. In order to divide x by y, we will subtract y from x until we reach a negative number. However, this time we actually have to keep track of the number of times we perform the subtraction.

So we start by copying the first number to box 0, and the second number to box 1. We will also initialize our divisor count by copying the zero in box 9 to somewhere else like box 3. Then we will copy the content of box 0 and subtract the content of box 1.

If, after this subtraction, we have a negative number, then whatever the answer we want to bring to the OUTBOX is whatever our count in box 3 is up to. If it's not, we want to copy the difference back to box 0, and bump box 3 up by one, and then start the subtraction step again.

Accounting for the usual optimization of placing the OUTBOX command above the INBOX command, you program may resemble the following:

   JUMP     b
a:
   COPYFROM 3
   OUTBOX
b:
   INBOX
   COPYTO   0
   INBOX
   COPYTO   1
   COPYFROM 9
   COPYTO   3
c:
   COPYFROM 0
   SUB      1
   JUMPN    a
   COPYTO   0
   BUMPUP   3
   JUMP     c

Optimizing[edit]

The above program meets the size challenge, and beats the speed challenge. It's already optimized by moving the OUTBOX command above the INBOX command. While it's possible to write a faster solution, it would require a significant amount of special case code that is not trivial to generate.