Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input = []) {
- let firesWithCell = input.shift().split('#');
- let water = Number(input.pop());
- let totalFire = 0;
- let effort = 0;
- let res = 'Cells:'
- let cellsArr = [];
- for (let i = 0; i < firesWithCell.length; i++) {
- let type = firesWithCell[i].split(' = ')[0];
- let cell = Number(firesWithCell[i].split(' = ')[1]);
- if (water <= 0) {
- break;
- }
- if (type === 'High' && cell >= 81 && cell <= 125 && water >= cell) {
- cellsArr.push(cell);
- effort += cell * 0.25;
- totalFire += cell;
- water -= cell;
- }
- if (type === 'Medium' && cell >= 51 && cell <= 80 && water >= cell) {
- cellsArr.push(cell);
- effort += cell * 0.25;
- totalFire += cell;
- water -= cell;
- }
- if (type === 'Low' && cell >= 1 && cell <= 50 && water >= cell) {
- cellsArr.push(cell);
- effort += cell * 0.25;
- totalFire += cell;
- water -= cell;
- }
- }
- console.log("Cells:");
- for (const oneCell of cellsArr) {
- console.log(` - ${oneCell}`);
- }
- console.log(`Effort: ${effort.toFixed(2)}`);
- console.log(`Total Fire: ${totalFire}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement