Ledger Nano X - The secure hardware wallet
SHARE
TWEET

03. Moving Target

t_sh0w Apr 7th, 2020 163 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let targets = input.shift().split(" ").map(Number);
  3.   input.pop();
  4.  
  5.   for (const currentLine of input) {
  6.     let [command, index, token] = currentLine.split(" ");
  7.     index = Number(index);
  8.     token = Number(token);
  9.  
  10.     switch (command) {
  11.       case "Shoot":
  12.         if (0 <= index && index <= targets.length - 1) {
  13.           targets[index] -= token;
  14.  
  15.           if (targets[index] <= 0) {
  16.             targets.splice(index, 1);
  17.           }
  18.         }
  19.         break;
  20.  
  21.       case "Add":
  22.         if (0 <= index && index <= targets.length - 1) {
  23.           targets.splice(index, 0, token);
  24.         } else {
  25.           console.log("Invalid placement!");
  26.         }
  27.         break;
  28.  
  29.       case "Strike":
  30.         if (0 <= index - token && index + token <= targets.length - 1) {
  31.           targets.splice(index - token, token + 1 + token);
  32.         } else {
  33.           console.log("Strike missed!");
  34.         }
  35.         break;
  36.     }
  37.   }
  38.   console.log(targets.join("|"));
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top