Advertisement
Guest User

Power of Thor

a guest
Jul 27th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var inputs = readline().split(' ');
  2. var lightX = parseInt(inputs[0]); // the X position of the light of power
  3. var lightY = parseInt(inputs[1]); // the Y position of the light of power
  4. var initialTX = parseInt(inputs[2]); // Thor's starting X position
  5. var initialTY = parseInt(inputs[3]); // Thor's starting Y position
  6.  
  7. // game loop
  8. while (true) {
  9.     var remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.
  10.     var turn_diff_TX = Math.max(initialTX, lightX) - Math.min(initialTX, lightX); // Difference between Thor's inital X position and the X position of the light.
  11.     var turn_diff_TY = Math.max(initialTY, lightY) - Math.min(initialTY, lightY); // Difference between Thor's initial Y position and the Y position of the light.
  12.    
  13.     /**
  14.      * If initalTX (Thor's X position) is bigger than lightX (X position of the light)
  15.      * then move the differene (turn_diff_TX) between the two to east ("E").
  16.      *
  17.      * If initialTX is smaller than lightX then move the difference to west ("W").
  18.      *
  19.      * If initialTX is equal to lightX then don't move.
  20.      **/
  21.      
  22.     if (initialTX > lightX) {
  23.         for (var i = 0; i < turn_diff_TX; i++)
  24.             print("W");
  25.     } else if (initialTX < lightX) {
  26.         for (var i = 0; i < turn_diff_TX; i++)
  27.             print("E");
  28.     } else if (initialTX == lightX){
  29.        
  30.     }
  31.    
  32.     /**
  33.      * If initalTY (Thor's Y position) is bigger than lightY (Y position of the light)
  34.      * then move the differene (turn_diff_TY) between the two to east ("E").
  35.      *
  36.      * If initialTY is smaller than lightY then move to west ("W").
  37.      *
  38.      * If initialTY is equal to lightY then don't move.
  39.      **/
  40.    
  41.     if (initialTY > lightY) {
  42.         for (var i = 0; i < turn_diff_TY; i++)
  43.             print("N");
  44.     } else if (initialTY < lightY){
  45.         for (var i = 0; i < turn_diff_TY; i++)
  46.             print("S");
  47.     } else if (initialTY == lightY){
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement