read_quest(1);
Killing some slimes
After long days of paperwork and chores, you’ve finally received your first real quest!
You can’t contain your excitement and quickly open the letter:
Okay… Time to read those instructions.
Let’s see.
Summoned Robot Instructions
Congratulations on acquiring our Monster-Killing Robot!
This manual provides essential instructions to ensure optimal performance and safety.
1. Available functions
The robot initialy has 4 possible functions:
Action | Description |
---|---|
up(); | Move the robot up one space |
down(); | Move the robot down one space |
left(); | Move the robot left one space |
right(); | Move the robot right one space |
More functions will be unlocked once enough monsters are defeated.
2. Usage
To kill a monster, just move the robot where it is and the machine will do the rest.
To ensure a 100% success rate, multiple simulations will run before executing your program.
This means that your code must be able to solve ALL the simulations at the same time.
3. Legal and Ethical Considerations
- Adhere to local laws and regulations governing the use of monster-killing robots.
- Exercise ethical judgement to ensure the safety of bystanders and property.
If you have any issue, don’t hesitate to reach out to our customer support for further assistance. We wish you a happy monster extermination!
Oops—while you were reading, one of these gelatinous things came up to you.
Remember the instructions:
up();
down();
left();
right();
Don’t forget the semicolon at the end of each function!
Kill the slime!
0 | 2 | |
3 | 4 | 5 |
6 | 8 |
Enter your code here...
Once the simulation is complete, the robot moves swiftly and punches the slime to death, well done!.
But the machine’s fighting isn’t specially stealthy, causing it to alert a nearby monster.
Finish another one!
0 | 1 | 2 |
4 | 5 | |
6 | 8 |
Enter your code here...
The robot is trying its best to follow your instructions, but the slime is surprisingly quick and manages to dodge every blow.
It seems like one simulation isn’t enough, let’s try with two!
Each “simulation” is represented by a different board.
Your code will need to solve all of them to be considered correct.
Try solving the first simulation and see what happens.
Complete the simulations!
0 | 2 | |
3 | 4 | 5 |
6 | 8 |
0 | 1 | 2 |
3 | 5 | |
6 | 8 |
Enter your code here...
This time, the monster tries to dodge like before, but the machine predicts the movement and blows it up with a very cool rocket fist.
New functions unlocked
Two new functions have been unlocked:
Action | Description |
---|---|
is_slime_left() | Returns true if a slime is located at the left of the robot.Works even if the slime is not adjacent. |
is_slime_right() | Returns true if a slime is located at the right of the robot.Works even if the slime is not adjacent. |
Great, new instructions!
But why would these unlock now?
…Well, here’s the answer.
Maybe we can use these to avoid unnecessary steps?
See the “Minimum Steps” message below every simulation?
This means that you have to solve it in that amount of steps.
To do it, you need to use the newly unlocked functions to check if there’s a slime to the left or right of the robot.
Try replacing the ?
with one of them and see what happens!
Let's use the new functions!
0 | 1 | 2 |
3 | 4 | 5 |
8 |
0 | 1 | 2 |
3 | 4 | 5 |
6 |
if ? { left(); } if ? { right(); }
Good! Work smarter, not harder. 😉
Unaware of your power, more slimes come to you.
If you’re receiving the “You don’t need more than two instructions” message, it means that the problem can be solved with a more general approach.
Read your code and see if you can simplify it.
For example, the following snippet:
Can be simplified to:
Murder those monsters!
0 | 1 | 2 |
3 | 4 | |
7 | 8 |
0 | 1 | 2 |
4 | 5 | |
6 | 7 |
if ? { } if ? { }
Well done, all slimes will tremble in fear when they hear your name!
…Or at least most of them, because the ones in front of you seem completely unfazed with your killing.
Let’s teach them a lesson!
If you’re in doubt, try solving it without accounting for the minimum steps and then think of what you can do to reduce them.
A good way to know when to use conditionals is to solve the problem aloud:
if the slime is on the left of the robot, go there, if not…
Different minimum steps?
0 | 2 | |
3 | 4 | 5 |
6 | 8 |
1 | 2 | |
3 | 4 | 5 |
6 | 8 |
Enter your code here...
You even handled a different number of steps for simulation, excellent job!
But then you hear a characteristic squish, you look behind and there they are—it’s an ambush!
WARNING WARNING, IMPOSSIBLE SITUATION FOUND, USE OF else
IS REQUIRED
Okay, I know if
, but… What’s this else
?
Think of else
as a default path if none of the above worked.
What will happen if the slime isn’t at the left of the robot when the if is_slime_left()
condition is reached?
Solve this, or else...
0 | 1 | 2 |
4 | 5 | |
6 | 8 |
0 | 2 | |
3 | 4 | 5 |
6 | 8 |
up(); if is_slime_left() { } else { }
No slimes in sight, at last, your job is done.
Or so you thought, because to your horror three slimes fall from the sky, prepared for the final fight.
You’re almost there. Hang on!
else if
is a special case of else
that allows you to check for another condition.
It’s especially useful because it only runs if the previous if
or else if
didn’t.
The final challenge!
0 | 1 | 2 |
4 | 5 | |
6 | 8 |
0 | 2 | |
3 | 4 | 5 |
6 | 8 |
0 | 1 | 2 |
3 | 4 | |
6 | 8 |
up(); if ? { } else if ? { } else { }
You did it! You saved the world from the slime invasion!
Well, maybe it wasn’t that dramatic, but you did a great job.
This was a long one though, so let’s take a break and celebrate your victory!
Join the Adventure!
Love Rust Quest?Your donation can help me keep writing and bring more chapters to life.