Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let targets = input.shift().split(' ');
  3.     let shotTargets = [];
  4.     let commands = {
  5.         end: "End"
  6.     }
  7.     for(let i=0; i < input.length; i++) {
  8.         console.log(targets)
  9.         if(input[i] === commands.end) {
  10.         } else {
  11.             if(input[i] < targets.length && !shotTargets.includes(targets[input[i]])) {
  12.                 for(let j = 0; j < targets.length; j++) {
  13.                     if(targets[j] < targets[input[i]] && shotTargets.includes(targets[input[i]])) {
  14.                         targets[j] = targets[j] - targets[input[i]]
  15.                     } else if( targets[input[i]] <= targets[j]   && !shotTargets.includes(targets[input[i]])) {
  16.                         targets[j] += targets[input[i]];
  17.                     }
  18.                 }
  19.                 targets[input[i]] = -1;
  20.                 shotTargets.push(targets[input[i]]);
  21.             }
  22.         }
  23.     }
  24. }
  25. solve([ '24 50 36 70', '0', '4', '3', '1', 'End' ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement