I can’t solve the whole thing but one!!!
like I can only solve one!!!
If you look to the left of the puzzle statement on https://www.codingame.com/ide/puzzle/power-of-thor-episode-1, you’ll find a HINTS button. Those hints may help you get started.
Also note that your code should be general enough to solve all the test cases.
#include
#include
#include
#include
using namespace std;
/**
- Solve this puzzle by writing the shortest code.
- Whitespaces (spaces, new lines, tabs…) are counted in the total amount of chars.
- These comments should be burnt after reading!
**/
int main()
{
int lx; // the X position of the light of power
int ly; // the Y position of the light of power
int tx; // Thor’s starting X position
int ty; // Thor’s starting Y position
cin >> lx >> ly >> tx >> ty; cin.ignore();
int tX;
int tY;
tX = initialTX;
tY = initialTY;
string dir;
// game loop
while (1) {
int remaining_turns; // The level of Thor's remaining energy, representing the number of moves he can still make.
cin >> remainingturns; cin.ignore();
if ((tX > lightX && (tY > lightY)) { tX -= 1; tY -= 1; dir = "NW"; }
else if ((tX > lightX && (tY < lightY)) { tX -= 1; tY += 1; dir = "SW"; }
else if ((tX < lightX && (tY < lightY)) { tX += 1; tY += 1; dir = "SE"; }
else if ((tX < lightX && (tY > lightY)) { tX += 1; tY -= 1; dir = "NE"; }
else if (tX > lightX) { tX -= 1; dir = "W"; }
else if (tX < lightX) { tX += 1; dir = "E"; }
else if (tY > lightY) { tY -= 1; dir = "N"; }
else if (tY < lightY) { tY += 1; dir = "S"; }
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
// A single line providing the move to be made: N NE E SE S SW W or NW
cout << dir << endl;
}
}
Is this a question or a solution?
a question for a solution
I’ll wait even if it costs my life!
can I be your friend?
Please stop spamming the forum. Study the error messages in the console after you run your code, and then try to fix the bugs accordingly.
i wrote this code but it is not working in c and i am only a 9th grader so please teach this to me i dont understand nothing
if(TY< LY) {printf(“E”);}
else if(LX < TX) {printf(“N”);}
else if(TY < LY) {printf(“S”);}
else {printf(“SE”);}
please tell me what is wrong
btw i wrote TY, LY, LX and LX because i changed the variables
You have to print a newline every time after you output the direction for a round.
Also, your code has to update the positions of Thor if it does not do so at the moment.
If you look to the left of the puzzle statement on https://www.codingame.com/ide/puzzle/power-of-thor-episode-1, you’ll find a HINTS button. More hints are available there.
I have a question:
Why does the following code fail ?
while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
dir = ""
if light_y != initial_ty :
if light_y-initial_ty > 0 :
dir = dir + "S"
elif light_y-initial_ty < 0 :
dir = dir + "N"
else:
dir=""
if light_x != initial_tx :
if light_x-initial_tx > 0 :
dir = dir + "E"
elif light_x-initial_tx < 0 :
dir = dir + "W"
# A single line providing the move to be made: N NE E SE S SW W or NW
print(dir)
This fails for an angle but by my understanding when the x or y coordinate becomes same thor should move in one direction like E or N and not SW or SE .
Sorry if this is stupid
You don’t seem to update Thor’s coordinates.
Ah i got it
Thanks man
sorry for the dumb question
[Mod edit: Please avoid posting full codes in the forum]
I don’t know why this codes works but i run out of steps, if you got some suggestions please tell me
You output O in one part of your code. O isn’t a direction recognised in this puzzle.
By the way, you use both light_x and lx, light_y and ly in different parts of your code, and that’s very confusing.
Lesson: always double-check variable names and string values to see if there are any typos ![]()
Please also avoid posting full codes in the forum in the future. Thanks.
Hello,
I don’t understand why my code doesn’t work.
For test 1 it’s ok.
Test 2 Thor go West while totaly unexpected and the test isn’t set on =< but on <… so the if shouldn’t activate.
And test 3 and 4 Thor goes on invalid position while being on a actual valid path to go to the hammer…
Any clue to help me understand my mistake ?
/**
* 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.
**/
// $lightX: the X position of the light of power
// $lightY: the Y position of the light of power
// $initialTx: Thor's starting X position
// $initialTy: Thor's starting Y position
fscanf(STDIN, "%d %d %d %d", $lightX, $lightY, $initialTx, $initialTy);
$deltaX = $lightX - $initialTx;
$deltaY = $lightY - $initialTy;
// game loop
while (TRUE)
{
$dirX = "";
$dirY = "";
$reponse = "";
// $remainingTurns: The remaining amount of turns Thor can move. Do not remove this line.
fscanf(STDIN, "%d", $remainingTurns);
if($deltaX > "0")
{
$dirX = "E";
$deltaX --;
}
elseif($deltaX < "0")
{
$dirX = "W";
$deltaX ++;
}
if($deltaY > "0")
{
$dirY = "S";
$deltaX ++;
}
elseif($deltaY < "0")
{
$dirY = "N";
$deltaX --;
}
$reponse = $dirY;
$reponse .=$dirX;
echo($reponse."\n");
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
// A single line providing the move to be made: N NE E SE S SW W or NW
}
You’re modifying deltaX for all the conditions.
I’m so ashamed…
By the way, that fix the test 2 but not 3 and 4.
Treat it as a lesson. Remember to always check variable names in your future programs! ![]()
Now check if >, <, ++ and -- are put in correctly.