As you probably figured out you can’t actually get the updated positions. But what you can do is keep track of what is going on. I would set up a two variables outside of your game loop. One for your X position and another for your Y position. Set them initially to Thor’s start position and then just update them every time you move. Doing this will give you Thor’s current position ever iteration of the loop.
Thanks, that worked. Just to clarify, I kept track of the difference between the 2 positions, and updated that difference in every step. Hope that helps without spoiling anything!
Hello all,
This is my first time here, I’m not fluent in english so, probably I’ll made some mistakes here.
Here go!
My approach to pass in all tests, basically consist in divide the direction in two axis:
var h = ""; // Horizontal axis
var v = ""; // Vertical axis
Right, with that I can define how direction Thor will move in each axis, since the value for each direction is trivial, and now, I can define the value for each axis by some decision blocks, for example:
// Define horizontal direction
if(TX < LX)
{
TX++;
h = "E";
}
else if(TX > LX)
{
TX--;
h = "W";
}
And finally, the output can be called like this:
print(v + h);
That’s it!
Thanks
Hi ! With this Python3 code, I pass all the test but for an unknown reason I only get 50%. I can pass all the test, but after I submited it, it says that I didn’t passed test 2 and 3.
Can someone help me please ?
LX, LY, TX, TY = [int(i) for i in input().split()]
directionX = ""
directionY = ""
if TX > LX:
directionX = "W"
elif TX < LX:
directionX = "E"
if TY > LY:
directionY = "N"
elif TY < LY:
directionY = "S"
while True:
E = int(input())
if E == 19:
directionY = ""
if E == 31 and directionX == "W":
directionY = ""
print(directionY + directionX)
Thanks
When you submit your code, it’s checked on more tests to prevent hardcoding.
Your code is an excellent example of hardcoding.
You need to write a code able to handle ANY test, not only those provided.
Keep coding
same for me, Ruby
Hello, guys.Have a proplem there- somehow it doesn`t want to read this.Any ideas?
if (LX>TX && LY=TY) cout<<“E”<<endl;
if (LX<TX && LY=TY) cout<<“W”<<endl;
if (LY>TY && LX=TX) cout<<“S”<<endl;
if (LY<TY && LX=TX) cout<<“N”<<endl;
My eyes are bleeding.
Seriously speaking, it’s all tangled and if it was working, I’ll be worried, because you have mixed all in a single line without ‘;’ with ‘=’ instead of ‘==’, an inegality in a middle of a cout etc…
I hope that it is all because you did a bad copy-paste. Else try doing step by step, something like:
if (X == Y)
cout << "Something" << endl;
else if (X < Y)
cout << "other thing" << endl;
I am not able to crack 3rd test case. Though it matches the test case for W direction, it goes in to the SW. Here’s the snippet of my code. Please help me
You must have improper conditions. Try to be sure to use the following syntax:
if
else if
else if
else
and not just
if
if
if
that way you’ll be sure that only one code output. If it still write the wrong code, check your inegality, and you’ll solve it in no time
I think he got the other bug, the one whose the answer is given - for the first time - in post number x
, where x
is given by the following formula:
x = (√2²)⁴
@CvxFous I tried everything…did this in IDE(another) providing the position myself for every move ad there it works fine
@Florent Was that for me? If so, sorry bt i didn’t get u…please elaborate
Does anybody know what the 4th test(Optimal Angle) requires you to do? 3rd test(easy angle) works for me. Thor goes SW till the end of the map then W till the lighting. However on the 4th test Thor goes SE and over the edge. Edit: sorry, my bad(a TX-- instead of TX++), but still what’s the difference between tests 3 and 4?
Yes and he is right, this is a good hint/riddle to help you get the solution
Hint if you can’t find: reread the whole topic, your issue is depicted here
The difference is only that you have to do the less possible move you can, whereas the 3 has a large margin.
Try using SE SW NE NW if you aren’t, it saves you one move each time.
@Florent M sry, but i still didnot get u…please elaborate
Do some maths, think a little and you’ll find in no time.
Bah, after a week or two of decay, you all look the same to me.
Hi, I’m also having a problem. My code, though anything but optimal, passes all tests. Yet when I click “submit” it tells me that I haven’t passed any, and gives me zero points. I’ve tried and retested my code and clicked submit numerous times and keep getting the same result. I’m using JavaScript.
Note: I’ve left my code out of this post as I see the moderator has requested users not post code here in the comments.
Are you sure you didn’t hardcoded anything? I tested submission in both PHP and Javascript and got 100%. Anyway, in the report page, you can see how Thor’s moving in each test so you should be able to find what’s wrong.