Power Of Thor - Episode 1 - Puzzle discussion

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.

2 Likes

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 :slight_smile:

This is my code :smile:
First time so i have complexity code :smiley:

[EDIT: NO FULL CODE]

It’s worked for 4 cases :smiley:

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.

yeah! my code here ASCII art puzzle discussion holds 29k minutes

Seems like we missed something.
But yeah, the GHOM* striked again.

*The ‘Greath Hammer of Moderation’ was designed by Thor, so that we could apply Justice on the forum.

In part 1 and 2 (Straight line and Up), I get: Expected a movement (one of N, NE, E, SE, S, SW, W, NW) but found ‘E’
In part 3 and 4 it works until Thor has to move horizontaly or vertically, then he moves off the map.
What should I do?

Already asked 7 posts above and, without surprise, the answer didn’t changed: ‘E’ is the textual representation of a character (1 letter + 2 simple quotes), not the output of a string of one letter.

I’m working in Python 3 and I’m having problems with the print function.

From what I can tell by testing my code, all of it is functional, except I cannot work out how to concatenate the two strings I need to print out (the direction_x and direction_y values). When I write only [print(direction_x)] as the last line, it works for the first test - unsurprisingly, as that one does not require a movement on the y-axis - but obviously that’s not going to work for all of them. I tried [print(direction_x, direction_y)] thinking that would solve the problem, but to no avail. Thor only stands motionless and watches the world burn.

Bonjour
en C je ne sais pas comment afficher une variable pour debug. Par exemple la variable initialTY.
fprintf(stderr, “Debug messages…\n” );
???