-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpowerOfThor.js
More file actions
32 lines (26 loc) · 1010 Bytes
/
powerOfThor.js
File metadata and controls
32 lines (26 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 thorX = initialTX;
var thorY = initialTY;
// game loop
while (true) {
var remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.
//west or east ?
var directionX = '';
var directionY = '';
// Write an action using print()
// To debug: printErr('Debug messages...');
if (thorX !== lightX) {
directionX = (thorX > lightX) ? 'W' : 'E';
thorX += (directionX === 'E') ? 1 : -1;
}
if (thorY !== lightY) {
//north or south
directionY = (thorY > lightY) ? 'N' : 'S';
thorY += (directionY === 'S') ? 1 : -1;
}
print(directionY + directionX); // A single line providing the move to be made: N NE E SE S SW W or NW
}