Power Of Thor - Episode 1 - Puzzle discussion

try using

directionX = "";
1 Like

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?

1 Like

@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.

1 Like

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?