Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //02. Shoot for the Win
- function solve(array) {
- let count = 0;
- let aim = array.shift().split(' ').map(Number)
- let command = array.shift();
- let shoot = -1;
- while (command !== 'End') {
- let index = Number(command);
- if (index < aim.length && index >= 0) {
- if (aim[index] === -1) {
- } else {
- let currentNumber = aim[index];
- aim[index] = shoot;
- count++;
- for (let i = 0; i < aim.length; i++) {
- if (aim[i] > -1) {
- if (aim[i] > currentNumber) {
- aim[i] = aim[i] - currentNumber;
- } else {
- aim[i] = aim[i] + currentNumber;
- }
- }
- }
- }
- }
- command = array.shift();
- }
- console.log(`Shot targets: ${count} -> ${aim.join(' ')}`);
- }
- solve(['24 50 36 70', '0', '4', '3', '1', 'End']);
- solve(['30 30 12 60 54 66',5,2,4,0,'End']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement