Advertisement
nikolayneykov

Untitled

Mar 12th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(params) {
  2.     let days = +params.shift();
  3.     let playerCount = +params.shift();
  4.     let groupEnergy = +params.shift();
  5.     let waterPerDay = +params.shift();
  6.     let foodPerDay = +params.shift();
  7.  
  8.     let totalWater = days * playerCount * waterPerDay;
  9.     let totalFood = days * playerCount * foodPerDay;
  10.  
  11.     let currentDay = 1;
  12.     for (let energy of params.map(Number)) {
  13.         groupEnergy -= energy;
  14.  
  15.         if (groupEnergy <= 0) {
  16.             break;
  17.         }
  18.  
  19.         if (currentDay % 2 === 0) {
  20.             groupEnergy *= 1.05;
  21.             totalWater *= 0.7;
  22.         }
  23.  
  24.         if (currentDay % 3 === 0) {
  25.             groupEnergy *= 1.1;
  26.             totalFood -= totalFood / playerCount;
  27.         }
  28.  
  29.         currentDay++;
  30.     }
  31.  
  32.     if (groupEnergy > 0) {
  33.         console.log(`You are ready for the quest. You will be left with - ${groupEnergy.toFixed(2)} energy!`);
  34.     } else {
  35.         console.log(`You will run out of energy. You will be left with ${totalFood.toFixed(2)} food ` +
  36.             `and ${totalWater.toFixed(2)} water.`);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement