Wrong: directionX is printed, and a NUL char is printed for directionY, which is not visible but still rejected by the validator.
well then, iāve posted working variant of C code upper in topic - please find and refer
same problemā¦ after few turns Thor is always leaving the mapā¦ he keeps going in the direction from previous turns
try using
directionX = "";
I need some help with the code, But I just canāt seem to be able to get Thor to change direction, a direction is chosen, but then he doesnāt change it when he should. Has anyone had this problem? If so, could you please give me a hint as to how to solve it?
@GordonDrake @emeeu @wajdi_feki88 Your program only gets the initial position of Thor and the light. Everytime Thor moves you have to update his position. Otherwise your program will choose the same direction every turn (the direction that was right for the first turn) and never change direction.
I think thorX and thorY are suppused to be defined before the loop. The strings in the loop. Correct me if Iām wrong.
Is the āstringā type allowed in C?
I have inicialised the char directionX/Y=0;
I also update the thorX/Y++
of course in the IFs, like:
if ( thorX < lightx ) { directionX=āEā; thorX++;}
in the end I printf("%c%c\n",directionY,directionX);
I read through the whole forum and I could not find the answer. Your code may be right but I donāt want just to copy it and donāt understand.
Help please.
When Thor only has to move in one direction the expected output is one character and a newline.
If you use printf("%c%c\n",directionY,directionX);
you are outputting two characters and a newline.
you picked my reply to c++ solution of puzzle, if you need pure c look at this Power Of Thor - Episode 1 - Puzzle discussion
how to do the easy angle test? i donāt know what i have to do
Iām not sure that strcat() is the easiest function to get right for a beginnner in C. In fact, this example code is not correct since char s[1]
is too short. Its length should be at least 2 to hold a single char string like "N"
.
IMHO, for the Thor problem, the simplest solution is to output the direction a soon as it is known, and to finalize with a newline:
if (/* want to go to the North*/) {
printf("N");
} else if (/* want to go to the South*/)
/* ... */
}
if (/* want to go to the West */) {
printf("W");
/* ... */
}
printf("\n");
If you really want to have a single call to printf
, using strings (AKA pointers to char) instead of chars for directionX
and directionY
is less error prone:
const char *directionX = "";
const char *directionY = "";
if (/* want to go to the North */) {
directionY = "N";
} else if (/* want to go to the South */) {
/* ... */
}
if (/* want to go to the West */) {
directionX = "W";
/* ... */
}
printf("%s%s\n", directionY, directionX);
Finally, note that the examples given above need to be completed to handle all directions, to update Thorās position, and so on.
Thank you very much, I was stagnating on a syntax problem. And I did not try to use pointers. Also I have a mess in apostrophes. Never know which ones to use. Iām just beginning with C so thereās so much I have to learn.
It seems like there is a bug for the second level. I am doing it in Python and as already mentioned, Thor goes to south instead of going north ?
AND ! It also makes my firefox crashā¦ Donāt know why :ā(ā¦
A) Probability that the easiest challenge of CG that has been successfully completed by thousands of coders has a bug: 0.0001 %.
B) Probability that your code has a bug: 99.9999 %.
Hint: this problem is so easily solved that some people can solve it in just 46 characters (for the record, your message is more than x4 longer).
Soluce: change any a - b
formula into your code into b - a
until Firefox stop crashing.
Hi
I got : Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found āEā
And thatās mindfuck
I guess you are either missing a newline or you are printing a ānot printableā character.
Well I used char. I solved it by using string
This is my code
First time so i have complexity code
[EDIT: NO FULL CODE]
Itās worked for 4 cases
When one see a posted code, one needs to count the minutes until its author get striked by the Lighting of Moderation. The distance ofĀ the moderator to its desk could then be derived by the mean of a simple division.