Human Resource Machine: A Programming Game Worth Playing
· 12 min read · Views --
Last updated on

Human Resource Machine: A Programming Game Worth Playing

Author: Alex Xiang


Human Resource Machine: A Programming Game Worth Playing

Human Resource Machine, usually abbreviated as HRM, is a classic programming game. Its structure is simple, but it has real depth. When teaching beginners the basics of programming, this game is worth recommending because it trains programming thinking directly.

Many beginner programming courses for children now choose Python first. That is reasonable. Python is relatively easy to learn, can produce satisfying results quickly, and is useful in real production scenarios. It is not only a teaching language or a toy. Compared with Scratch or Lego-style visual programming, Python has broader long-term value.

But if beginners only use Python, they may miss some low-level programming ideas. C is closer to the machine, but it is not always suitable for young beginners. It is less entertaining and may discourage people at the start.

That is where Human Resource Machine is interesting.

On the surface, it is a puzzle game. Underneath, it behaves like a tiny computer system. It has input and output. The floor tiles can be understood as temporary storage, similar to registers. The office worker is an execution unit that fetches and executes instructions, moving data between input, output, and storage.

The program that the worker executes resembles a low-level programming language. It has instructions such as:

  • Data input and output: INBOX, OUTBOX
  • Arithmetic: ADD, SUB
  • Storage access: COPYTO, COPYFROM
  • Jumps: JUMP, JUMPIFZERO

HRM’s instruction set is tiny, roughly around ten instructions. At first glance it seems too small to do much. Even simple tasks need many steps. But if you think through it carefully, you begin to see how computers execute programs at the most fundamental level. In a sense, HRM’s instruction system sits close to assembly language or even machine language.

For example, to add two numbers and output the result, HRM uses this instruction sequence:

inbox
copyto 0
inbox
add 0
outbox

The worker reads instructions, gets data from the inbox, writes data to the outbox, and uses storage tiles when needed. Here is a simplified instruction table:

InstructionOperandMeaning
inboxTake the first item from the input conveyor. The previous current item is discarded. If there is no input, the program ends.
outboxPut the current item onto the output conveyor. The worker no longer holds it.
addXAdd the value on floor tile X to the current item. Tile X remains unchanged.
subXSubtract the value on floor tile X from the current item. Tile X remains unchanged.
copytoXCopy the current item to tile X. If tile X already has an item, it is overwritten.
copyfromXCopy the item on tile X into the worker’s hand.
jumpXContinue execution from instruction X.
jumpifzeroXIf the current item is 0, jump to instruction X; otherwise continue.

There are a few other instructions in the game, but these are enough for the idea.

Now look again at the addition example. At the machine level, it means:

Read a number from input
Store it in register 0
Read another number from input
Add the value in register 0
Output the result

It looks verbose, but this is close to how computers work internally.

Here is a slightly more complex program:

INBOX
COPYTO   0
ADD      0
COPYTO   0
ADD      0
COPYTO   0
ADD      0
COPYTO   0
ADD      0
ADD      0
ADD      0
ADD      0
OUTBOX
JUMP     1

This program multiplies an input number by 40. It is worth thinking through how it achieves that result using only addition and storage.

If you are interested, play the game. You can find walkthrough videos on Bilibili, and complete solution repositories on GitHub, such as:

https://github.com/atesgoral/hrm-solutions

Each level has multiple solutions. File names often reveal differences in instruction count and runtime. That is another useful lesson: a program can be correct, but still differ in size and execution cost.

HRM is a strong starting point. With some extension, it could become a more practical programming-introduction tool.