# How do you complete the speed challenge for Zero Preservation Initiative

In Human Resource Machine, each stage starting with Year 6 has two bonus objectives.

In Year 9, the Speed Challenge is to get it in 25 steps. However, my solution (the standard programming solution) takes 28 steps.

In this puzzle, you must move all 0 inputs to the Outbox. There are 8 inputs and 4-5 of them are 0.

Here's what I came up with

``````-- HUMAN RESOURCE MACHINE PROGRAM --

a:
b:
INBOX
JUMPZ    c
JUMP     b
c:
OUTBOX
JUMP     a
``````

In the above, each 0 takes 4 steps and each non-0 takes 3 steps. On average, it's saying this takes 28 steps.

What is the correct sequence to complete this in 25 or less steps?

``````-- HUMAN RESOURCE MACHINE PROGRAM --

JUMP     b
a:
OUTBOX
b:
c:
INBOX
JUMPZ    a
JUMP     c
``````

This is based on DJ Pirtu's solution, but solves it with both the size and speed challenges, without relying on the first input being non-zero.

• I don't understand why this is more efficient than the solution in the question. – Ant Aug 15 '19 at 23:22
• @Ant, since except for the first run, all runs only take 3 steps. The optimization lies in only needing a single jump in the 'zero' case. – Steven Jeuris Aug 20 '19 at 22:56

The following code does speed challenge in 21 steps: It relies on the fact that first number in the input is non-zero and second is zero..just noticed this pattern and the game didn't complain so...

``````-- HUMAN RESOURCE MACHINE PROGRAM --

INBOX
INBOX
a:
OUTBOX
b:
INBOX
JUMPZ    a
JUMP     b
``````

if you don't want to skip first number and do it in 24 steps :

``````-- HUMAN RESOURCE MACHINE PROGRAM --

a:
INBOX
JUMPZ    b
JUMP     a
b:
c:
OUTBOX
d:
INBOX
JUMPZ    c
JUMP     d
``````
• You need to be careful about assuming the order of inputs. Usually, the computer will come yell at you this what you did works for the current set of inputs and promply give you another set it will fail for. – Powerlord Oct 16 '15 at 20:21