Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(...input) {
- let drugCounter = Number(input.shift());
- let drugVolume = drugCounter * 750;
- let counter = 1;
- let dishCount = input.shift();
- let dishes = 0;
- let pots = 0;
- while(dishCount != 'End') {
- if (typeof dishCount != Number) {
- dishCount = Number(dishCount);
- }
- if (drugVolume < 0) {
- console.log(`Not enough detergent, ${Math.abs(drugVolume)} ml. more necessary!`);
- break;
- }
- if (counter % 3 == 0) {
- drugVolume = drugVolume - (dishCount * 15);
- pots += dishCount;
- } else {
- drugVolume = drugVolume - (dishCount * 5);
- dishes += dishCount;
- }
- dishCount = input.shift();
- counter++;
- }
- if(drugVolume >= 0) {
- console.log(`Detergent was enough!`);
- console.log(`${dishes} dishes and ${pots} pots were washed.`);
- console.log(`Leftover detergent ${drugVolume} ml.`);
- }
- }
- solve(2, 53, 65, 55, 'End');
- solve(1, 10, 15, 10, 12, 13, 30);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement