desito07

Counter Strike

Jun 23rd, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function solve(input) {
  2. let energy = Number(input.shift());
  3. let command = input.shift();
  4. let counter = 0;
  5. let isLost = false;
  6. while (command !== "End of battle") {
  7. let currentDistance = Number(command);
  8. energy -= currentDistance;
  9. counter++;
  10. if (counter % 3 === 0) {
  11. energy += counter;
  12. }
  13.  
  14. if (energy <= 0) {
  15. isLost = true;
  16. console.log(
  17. `Not enough energy! Game ends with ${counter} won battles and ${energy} energy`
  18. );
  19. break;
  20. }
  21. command = input.shift();
  22. }
  23. if (command === "End of battle") {
  24. console.log(`Won battles: ${counter}. Energy left: ${energy}`);
  25. }
  26. }
  27. solve(["100", "10", "10", "10", "1", "2", "3", "73", "10"]);
  28. solve(["200", "54", "14", "28", "13", "End of battle"]);
Advertisement
Add Comment
Please, Sign In to add comment