As mentioned, this one is broken. After fighting with it for a while to try to override the “walked off the map” error (including setting hard limits at Y=17 and Y=0), I flat out pasted in the solution code to see what I was doing wrong, and that also didn’t work. I was using Javascript.
I’ve just tried using the solution code in the hints. Nothing’s broken, nothing’s wrong.
I have a valid C++ solution that passes all tests in IDE, but only 75% after submit.
Can’t understand why this bug still be…
The validators that are used to assess your code to give you the final score are different from the visible test cases. Hence, your code has to be general enough to pass the validators too.
The game has a bug in “bash” language. The test “Easy Angle (Angle facile)” don’t work because the time is not enough.
It’s perfectly doable and not buggy. There are existing solutions in that language.
Thank you for your reply. But I think It’s a bug because it works with [-condition-] (time is 31), but with [[-condition-]] it doesn’t work (time is 14).
It sounds like a bug in your code rather than a bug of the puzzle itself. Perhaps you should check why your code does not output correctly after 14 turns.
This may be because a computer takes its y from top to bottom instead of the intuitive way you would show on a graph.
The game says that initialTX is the starting postioin of thor (X) but when i try to make an If condition with it, it says that initialTX is not defined? (javascript)
The variable names may be a bit different in different programming languages. You should always refer to what are used in the default code and follow them, or you can choose to change them all. In the case of javascript, the variable name used there is initialTx.
switch{
case thorX > lightX:
directionX = "W"
thorX--
case thorX < lightX:
directionX = "E"
thorX++
}
switch{
case thorY > lightY:
directionY = "N"
thorY--
case thorY < lightY:
directionY = "S"
thorY++
}
Go question, why does test case 4 fail if i have them all in one switch?
The code you have posted is using 2 switches. When you say “all in one switch” do you still refer to the code you have posted, or is it a modified version of the code?
Also just to make sure we are looking at the same thing: are you talking about test case 4, or validator 4? Test case 4 works fine when I replace part of the answer code in the HINTS section with your code.
It depends on if switch
allows you to match multiple case
s or not.
Test case 4. It passed all other tests when all conditions were in the same switch.
Putting all conditions within a single switch does not work because the N/S condition and the W/E condition are not mutually exclusive. When you put them all within a single switch it means when one of the conditions is met, all the remaining conditions in the switch will be ignored by the code.
Hi, I begin to learn C++. After passed hours on my code I couldn’t find the mistakes. It’s feels like if the “==” didn’t worked.
when I used == to compare values the program just didn’t do it.
Have you an idea of where my problem could be?
The code :
#include
#include
#include
#include
using namespace std;
/**
- Auto-generated code below aims at helping you parse
- the standard input according to the problem statement.
-
- Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
**/
int main()
{
int light_x; // the X position of the light of power
int light_y; // the Y position of the light of power
int initial_tx; // Thor’s starting X position
int initial_ty; // Thor’s starting Y position
cin >> light_x >> light_y >> initial_tx >> initial_ty; cin.ignore();
int posX=initial_tx;
int posY=initial_ty;
// game loop
while (1) {
int remaining_turns; // The remaining amount of turns Thor can move. Do not remove this line.
cin >> remaining_turns; cin.ignore();
int dx;
int dy;
string move_x= "";
string move_y= "";
dx = light_x - posX;
dy = light_y - posY;
if (posX < light_x){
move_x = "E";
posX = posX +1;
} else if (posX > light_x){
move_x = "W";
posX = posX -1;
}
if (posY > light_y){
move_y = "N";
posY = posY +1;
}else if (posY<light_y){
move_y = "S";
posY = posY -1;
}
if (dx*dx == dy*dy){
cout << move_y << move_x << endl;
} else if (move_x != ""){
if (move_y != "S"){
posY = posY +1;
}else {
posY = posY -1;
}
cout << move_x << endl;
}else if (move_y != ""){
if (move_x != "W"){
posY = posY +1;
}else {
posY = posY -1;
}
cout << move_y << endl;
}
}
}
thanks for your advice,
I don’t understand the logic of dx * dx == dy * dy.
For example,
When dx = 1, dy = 1, the output should be SE.
When dx = 2, dy = 1, the output should be SE.
When dx = 3, dy = 1, the output should be SE.
But dx * dx == dy * dy holds true in one of the above cases only.
the line dxdx == dydy is here to solve the case even if dx<0 and dy>0 it’s because I didn’t find the function abs(dx)
it’s weird, for exemple during the first step of the puzzle : dy==0 cause posY=light_y but the function cout" << move_x << endl " didn’t worked
You can use abs in C++. Please google the syntax for that. However, the simplest way is just to test dx != 0 and dy != 0.