Advertisement
t_sh0w

01. Counter Strike

Apr 7th, 2020
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let initialEnergy = Number(input.shift());
  3.   let isNotEnough = false;
  4.   let winsCounter = 0;
  5.   let currentLine = input.shift();
  6.  
  7.   while (currentLine !== "End of battle") {
  8.     currentDistance = Number(currentLine);
  9.     initialEnergy -= currentDistance;
  10.  
  11.     if (initialEnergy < 0) {
  12.       isNotEnough = true;
  13.       initialEnergy += currentDistance;
  14.       break;
  15.     }
  16.     winsCounter++;
  17.  
  18.     if (winsCounter % 3 === 0) {
  19.       initialEnergy += winsCounter;
  20.     }
  21.  
  22.     currentLine = input.shift();
  23.   }
  24.   if (isNotEnough) {
  25.     console.log(`Not enough energy! Game ends with ${winsCounter} won battles and ${initialEnergy} energy`);
  26.   } else {
  27.     console.log(`Won battles: ${winsCounter}. Energy left: ${initialEnergy}`);
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement