Could you please explain a bit more about what you’re trying to do, like, how you intend to move Thor? I’m afraid I can’t understand your message.
If you want to reduce the number of turns to move Thor, you should move Thor in a diagonal direction as many times as needed. For example, if you move Thor N and then E, that’ll take two turns, while it takes just one turn to move Thor NE directly.
it’s more, i’m looking to make the code smaller? like, after i figured out the X Y axis idea, to go N +/- 1 depending on initial_ty. I wanted to see if i can condense the script for the code? is there any way instead of doing +/- = 1 on the X/Y axis, without having to utilize numbers? or is the most efficient way of reaching the destination just +/- 1?
Once you’ve got the initial data, you can already plan ahead what moves to do without referring to subsequent data. Maybe that’ll help you condense the script in some way? But even then, you still have to “utilize numbers” for at least one turn.
right. i feel like doing if thor_x > light_x:
direction_x = “W”
thor_x -= 1
isn’t good enough in a sense? to have one string per direction feels like it needs to be made more efficient so i’m trying to figure out how i can create a string that makes Thor move without as much lines of code.
Whitespaces (spaces, new lines, tabs…) are counted in the total amount of chars.
These comments should be burnt after reading!
**/
int main()
{
int lx; // the X position of the light of power
int ly; // the Y position of the light of power
int tx; // Thor’s starting X position
int ty; // Thor’s starting Y position
cin >> lx >> ly >> tx >> ty; cin.ignore();
int tX;
int tY;
tX = initialTX;
tY = initialTY;
string dir;
// game loop
while (1) {
int remaining_turns; // The level of Thor's remaining energy, representing the number of moves he can still make.
cin >> remainingturns; cin.ignore();
if ((tX > lightX && (tY > lightY)) { tX -= 1; tY -= 1; dir = "NW"; }
else if ((tX > lightX && (tY < lightY)) { tX -= 1; tY += 1; dir = "SW"; }
else if ((tX < lightX && (tY < lightY)) { tX += 1; tY += 1; dir = "SE"; }
else if ((tX < lightX && (tY > lightY)) { tX += 1; tY -= 1; dir = "NE"; }
else if (tX > lightX) { tX -= 1; dir = "W"; }
else if (tX < lightX) { tX += 1; dir = "E"; }
else if (tY > lightY) { tY -= 1; dir = "N"; }
else if (tY < lightY) { tY += 1; dir = "S"; }
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
// A single line providing the move to be made: N NE E SE S SW W or NW
cout << dir << endl;
}
i wrote this code but it is not working in c and i am only a 9th grader so please teach this to me i dont understand nothing
if(TY< LY) {printf(“E”);}
else if(LX < TX) {printf(“N”);}
else if(TY < LY) {printf(“S”);}
else {printf(“SE”);}
please tell me what is wrong
btw i wrote TY, LY, LX and LX because i changed the variables
while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
# Write an action using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)
dir = ""
if light_y != initial_ty :
if light_y-initial_ty > 0 :
dir = dir + "S"
elif light_y-initial_ty < 0 :
dir = dir + "N"
else:
dir=""
if light_x != initial_tx :
if light_x-initial_tx > 0 :
dir = dir + "E"
elif light_x-initial_tx < 0 :
dir = dir + "W"
# A single line providing the move to be made: N NE E SE S SW W or NW
print(dir)
This fails for an angle but by my understanding when the x or y coordinate becomes same thor should move in one direction like E or N and not SW or SE .