-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOWER OF THOR.js
More file actions
33 lines (29 loc) · 1.03 KB
/
POWER OF THOR.js
File metadata and controls
33 lines (29 loc) · 1.03 KB
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
33
var inputs = readline().split(" ");
const lightX = parseInt(inputs[0]); // the X position of the light of power
const lightY = parseInt(inputs[1]); // the Y position of the light of power
const initialTx = parseInt(inputs[2]); // Thor's starting X position
const initialTy = parseInt(inputs[3]); // Thor's starting Y position
let currentTx = parseInt(inputs[2]); // Thor's starting X position
let currentTy = parseInt(inputs[3]); // Thor's starting Y position
let direction = "";
// game loop
while (true) {
const remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.
if (currentTy > lightY) {
currentTy--;
direction = "N";
if (currentTx !== lightX) {
direction += initialTx < lightX ? "E" : "W";
}
} else if (currentTy < lightY) {
currentTy++;
direction = "S";
if (currentTx !== lightX) {
direction += initialTx < lightX ? "E" : "W";
}
} else {
direction = currentTx < lightX ? "E" : "W";
}
console.log(direction);
direction = "";
}