Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(params) {
- let days = +params.shift();
- let playerCount = +params.shift();
- let groupEnergy = +params.shift();
- let waterPerDay = +params.shift();
- let foodPerDay = +params.shift();
- let totalWater = days * playerCount * waterPerDay;
- let totalFood = days * playerCount * foodPerDay;
- let currentDay = 1;
- for (let energy of params.map(Number)) {
- groupEnergy -= energy;
- if (groupEnergy <= 0) {
- break;
- }
- if (currentDay % 2 === 0) {
- groupEnergy *= 1.05;
- totalWater *= 0.7;
- }
- if (currentDay % 3 === 0) {
- groupEnergy *= 1.1;
- totalFood -= totalFood / playerCount;
- }
- currentDay++;
- }
- if (groupEnergy > 0) {
- console.log(`You are ready for the quest. You will be left with - ${groupEnergy.toFixed(2)} energy!`);
- } else {
- console.log(`You will run out of energy. You will be left with ${totalFood.toFixed(2)} food ` +
- `and ${totalWater.toFixed(2)} water.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement