Skip to content

Instantly share code, notes, and snippets.

@catalinabustam
Last active June 17, 2017 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catalinabustam/2a2bc0cb49a099d2bca3d26a11c77969 to your computer and use it in GitHub Desktop.
Save catalinabustam/2a2bc0cb49a099d2bca3d26a11c77969 to your computer and use it in GitHub Desktop.
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
* ---
* Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
**/
var inputs = readline().split(' ');
var lightX = parseInt(inputs[0]); // the X position of the light of power
var lightY = parseInt(inputs[1]); // the Y position of the light of power
var initialTX = parseInt(inputs[2]); // Thor's starting X position
var initialTY = parseInt(inputs[3]); // Thor's starting Y position
var m_x = ''
var t_x = 0
var m_y = ''
var t_y = 0
if (initialTX > lightX) {
m_x = 'W'
t_x = initialTX - lightX
}
else if (initialTX < lightX) {
m_x = 'E'
t_x = lightX - initialTX
}
if (initialTY > lightY) {
m_y = 'N'
t_y = initialTY - lightY
}
else if (initialTY < lightY) {
m_y = 'S'
t_y = lightY - initialTY
}
// game loop
while (true) {
var remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.
if (t_x == t_y) {
print(m_y.concat(m_x))
}
else if (t_x > 0){
print(m_x);
t_x -= 1
}
else{
print(m_y);
t_y -= 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment