As in my code the conditions are applied correctly but after reaching on the same line of light in y direction it still goes down and reaches to an invalid position.
For eg.
Thor initial pos. :- (31,4) and light’s pos. :- (0,17)
After reaching the pos. (17,18) it moves forward to (18,17) in place of (17,17).
Please Help!!!
Do you update Thor’s coordinates?
hello,
I am doing Power of Thor in C,
but I don’t understand the issue, my code doesn’t work.
Can you put me in the way of my mistake.
my code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/**
* 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()
{
// the X position of the light of power
int light_x;
// the Y position of the light of power
int light_y;
// Thor's starting X position
int initial_tx;
// Thor's starting Y position
int initial_ty;
scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty);
// game loop
while (1) {
// The remaining amount of turns Thor can move. Do not remove this line.
int remaining_turns;
scanf("%d", &remaining_turns);
scanf("%d%d", &initial_tx, &initial_ty);
char *dir_y = "";
char *dir_x = "";
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf( stderr, "Debug messages...\n");
if(initial_tx < light_x)
{
dir_x = "E";
initial_tx ++;
}
else if(initial_tx > light_x)
{
dir_x = "W";
initial_tx --;
}
if(initial_ty < light_y)
{
dir_y = "S";
initial_ty ++;
}
else if (initial_ty > light_y)
{
dir_y = "N";
initial_ty --;
}
// A single line providing the move to be made: N NE E SE S SW W or NW
printf("%s %s", dir_x, dir_y);
}
return 0;
}
What is the error you get ?
Have you carefully read the comments in the default code ?
The error is that you’re trying to read Thor’s position at each turn of the game loop, but this information is not provided. It’s up to you to update this position in function of the moves you make…
Informations :
Timeout: your program did not provide an input in due time. Earth was destroyed!
It’s the only message i get.
I update the position in the function main().
I increment and decrement for each case in my “if function”.
Yes but you’ve put a scanf that’s waiting for the Thor’s position in your loop, and like no input come your program just wait indefinitely.
oh yes I nderstand.
but when I delete the scanF().
Thor don’t move.
However, the stdout for the first test is “E” but no move.
The message is:
Sortie standard :
E
Informations :
Timeout: your program did not provide an input in due time. Earth was destroyed!
I’m tearing my hair!
haven’t you forgotten to send “\n” ?
that a really common mistake …
You’re right.
I have forgotten this and it’s corrected. I don’t really understand the importance of this “\n” but…
Thor just move one time and stop.
// game loop
while (1) {
// The remaining amount of turns Thor can move. Do not remove this line.
int remaining_turns;
scanf("%d", &remaining_turns);
char *dir_y = "";
char *dir_x = "";
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf( stderr, "Debug messages...\n");
if(initial_tx < light_x)
{
dir_x = "E\n";
initial_tx ++;
}
else if(initial_tx > light_x)
{
dir_x = "W\n";
initial_tx --;
}
if(initial_ty < light_y)
{
dir_y = "S\n";
initial_ty ++;
}
else if (initial_ty > light_y)
{
dir_y = "N\n";
initial_ty --;
}
// A single line providing the move to be made: N NE E SE S SW W or NW
printf("%s %s", dir_x, dir_y);
}
I really don’t understand why. I don’t want the answer but just understand what is my mistake.
Attention : votre code n’a pas lu toutes les données disponibles depuis l’entrée standard avant d’avoir écrit sur la sortie standard. Ceci cause une désynchronisation qui peut entraîner des comportements inattendus.
Informations :
Thor’s ready to go. Thor position = (5,4). Light position = (31,4). Energy = 100
0 2
Sortie standard :
E
Informations :
Thor’s moving… Thor position = (6,4). Light position = (31,4). Energy = 99
1 2
Sortie standard :
E
Informations :
Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ’ E’
it tell me that my program write before have read all the data. it can be a cause of desynchronisation.
“\n” is mandatory to end the output for a turn.
you should put it in your printf.
moreover the message is correct.
your printf cannot send a valid output because you tell him to print 2 strings separated by a space. even if dir_x is an empty string there will be a space before dir_y (and a space after dir_x if dir_y empty)
the output format is clearly defined in puzzle’s statement.
wow, yes I don’t note this space. I wanted to make my code more readable, and add this space was a mistake.
Thanks a lot.
I validate all the tests except the last one, the optimal angle. I work on it
thanks for your time!
Hello too.
Nobody can help you if you are not a little specific in your question (Is that a question ?)
What language do you use ? On which tests is the problem happening ? Can you show us your code ?
With these informations no doubt somebody will help you… If you’re a little more polite.
Hi everyone.
I just completed the first step of the Power Of Thor.
My code works using this statement : while (true) {conditions related to Thor positions}.
I am confused because I don’t understand why this is correct. From my understanding this should not be, because for me “While (true)” should generate an infinite loop. There is even no “break” statement in the block of code that is executed in the loop, and still the Episode 1 seems completed.
Please, can you tell me I am not crazy. Is it just syntax sugar or the site that is making things easy for us as beginners ?
Thank you for your answers, I am sure they will help me.
Of course you’re crazy…
It’s because the turn count is not known. Your code will run until the site stop it (Turn limit reached, failure or victory).
It’s a typical situation when the puzzle has the “game” format.
Your script is not a standalone, it interacts with the game script. The game scripts analyzes your outputs one by one and updates the game situation.
When a halting condition is met (defeat/victory), the game script stops the game itself.
It’s different with classic puzzles, where there is no game script, only a whole list of inputs fed to the stdin.
You capture the inputs as you want, as a whole or one by one, it doesn’t matter, and you return outputs.
Your whole output is then compared to the expected one to know if you completed the puzzle or not.
It has to be exactly as expected.
While in the “game” format, there are usually several ways to win the game, in Thor for example if you do E then NE it will lead to the same outcome as if you do NE then E.
can someone please teach me to do more then one codes and when i put fmt.Println(“SW”) and fmt.Println(“w”) they dont go so well.
If you print w it won’t work, you must print an uppercase W.