hrm.i8c.net
Open in
urlscan Pro
139.162.42.49
Public Scan
URL:
https://hrm.i8c.net/
Submission: On December 23 via api from US — Scanned from SG
Submission: On December 23 via api from US — Scanned from SG
Form analysis
0 forms found in the DOMText Content
NAV * Introduction * Levels * Year 1 Mail Room * Solution * Year 2 Busy Mail Room * Optimized for Size * Loop Unroll for Speed * INBOX before JUMP for Speed * Year 3 Copy Floor * Solution * Year 4 Scrambler Handler * Solution * Year 6 Rainy Summer * Solution * Optimization * Optimization Techniques * Speed Optimization * Loop Unroll * INBOX before JUMP * Exceptional Circumstances * Ending Execution * Program Length * Infinite Loops * See also atesgoral’s solution collection * Open-source icons created by Ida Desi Mariana - Flaticon INTRODUCTION Human Resource Machine is a programming puzzle game by Tomorrow Corporation. It teaches programming concepts and program flow, and includes optimization goals for size and speed. This walkthrough describes straightforward answers for select levels, then explores the methods that can be used to reach the optimization goals. There are two optimization goals for each level: * The size optimization goal seeks the smallest program that achieves the level goal. * The speed optimization goal seeks the program that achieves the level goal in the shortest time. Each command processed takes one time unit. There is a section at the end summarizing the optimization techniques used. LEVELS YEAR 1 MAIL ROOM Grab each thing from the INBOX and drop it into the OUTBOX. * 6 or fewer instructions. * 6 or fewer steps. New instructions available: * INBOX: Get an item from the inbox. * OUTBOX: Put an item into the outbox, emptying our hands. SOLUTION INBOX OUTBOX INBOX OUTBOX INBOX OUTBOX > Copy three inbox items to the outbox. There is the only one approach in the Mail Room, since we only have two instructions available. Since the test data has up to three inputs we just do three INBOX instructions matched with three OUTBOX instructions. The initial solution satisfies the optimization goals. YEAR 2 BUSY MAIL ROOM Grab each thing from the INBOX and drop it into the OUTBOX. * 3 or fewer instructions. * 25 or fewer steps. We can either satisfy the size goal or the speed goal, but cannot satisfy both at the same time (since speed optimisation requires more than three instructions). New instructions available: * JUMP: Jump to another location in the code. OPTIMIZED FOR SIZE a: INBOX OUTBOX JUMP a > Copy inbox items to the outbox. Size 3, 30 steps. The smallest approach is to copy one item, then loop back to the start and copy the next item. This costs 3 steps per item, for a total of 30 steps. LOOP UNROLL FOR SPEED a: INBOX OUTBOX INBOX OUTBOX JUMP a > Loop unrolled version. Size 5, 25 steps. Loop unrolling is the process of copying the same block of instructions multiple times to save one JUMP instruction per copy. In this challenge the test data has up to 12 items. The most extreme loop unroll would result in 12 INBOX instructions with 12 matching OUTBOX instructions, giving a size of 24 and a worst time of 24 steps (average 20). INBOX BEFORE JUMP FOR SPEED INBOX a: OUTBOX INBOX OUTBOX INBOX JUMP a > Loop unrolled version with INBOX then JUMP optimisation. Size 6, 24 steps. INBOX before JUMP is a technique of moving the INBOX instruction that would occur after a JUMP instruction so that it occurs before that instruction. This saves one step overall, because the program stops when INBOX sees an empty inbox. Otherwise the final JUMP costs one step before INBOX ends the program. YEAR 3 COPY FLOOR Copy the letters “BUG” from the floor to the outbox. * 6 or fewer instructions. * 6 or fewer steps. New instructions available: * COPYFROM: Read a value from a tile on the floor. SOLUTION COPYFROM 4 OUTBOX COPYFROM 0 OUTBOX COPYFROM 3 OUTBOX > Copy the letters BUG from the floor to the outbox. Size 6, 6 steps. Since the floor has 6 tiles with letters, and only three of them are suitable for the goal, there is only one answer (unless you waste extra time on operations that don’t affect the outbox). The initial solution satisfies the optimization goals. YEAR 4 SCRAMBLER HANDLER For each two things in the inbox, swap their order and put them in the outbox. * 7 or fewer instructions. * 21 or fewer steps. New instructions available: * COPYTO: Read a value from a tile on the floor. SOLUTION a: INBOX COPYTO 1 INBOX OUTBOX COPYFROM 1 OUTBOX JUMP a > Swap the order of each pair of input items. Size 7, 21 steps. 1. Copies the first item from each pair to tile 1. 2. Puts the next item from the inbox directly into the outbox. 3. Finally read the first item from tile 1 and put it into the outbox. 4. Jump back to the start to process more items. The number of steps required could be reduced by unrolling the loop, however that would increase the number of instructions past the goal. The initial solution satisfies the optimization goals. YEAR 6 RAINY SUMMER For each two things in the inbox, add them and put the result in the outbox. * 6 or fewer instructions. * 24 or fewer steps. SOLUTION a: INBOX COPYTO 1 INBOX ADD 1 OUTBOX JUMP a > Add each pair of input items. Size 6, 24 steps. 1. Copies the first item from each pair to tile 1. 2. Gets the next item from the inbox and adds the first value (from tile 1). 3. Puts the result into the outbox. 4. Jump back to the start to process more items. The initial solution satisfies the optimization goals. OPTIMIZATION The number of steps required could be reduced by unrolling the loop, however that would increase the number of instructions past the goal. INBOX before JUMP would reduce the overall steps required by one, at the cost of one additional instruction. OPTIMIZATION TECHNIQUES SPEED OPTIMIZATION LOOP UNROLL INBOX OUTBOX INBOX OUTBOX INBOX OUTBOX > Three inbox to outbox commands, loop unrolled. Loop unrolling removes one JUMP step per copied code block at the size cost of the additional code block. INBOX BEFORE JUMP INBOX a: OUTBOX INBOX OUTBOX INBOX JUMP a > INBOX before JUMP saves one JUMP when inbox is empty. INBOX before JUMP remove one JUMP step for the final input item. It may have a size cost of one additional command depending on the program structure. EXCEPTIONAL CIRCUMSTANCES ENDING EXECUTION There are two ways to end execution and check for completion of the goals: * INBOX when the inbox is empty. * Let execution run off the end of the program. These actions end execution with an error: * OUTBOX with an unexpected value. * Attempting to use a value when you’re not holding one (e.g. after OUTBOX). PROGRAM LENGTH Programs can be up to 255 lines long. Both instructions and destinations for JUMP instructions count as lines. Nothing bad happends once you reach 255 lines, but you cannot add more instructions. INFINITE LOOPS Programs can run for a long time. Presumably you will eventually run out of memory (for stepping backwards in the debugger). code