Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve([fire, water]) {
- let fireCells = fire.split('#').map(x => x.split(' = '));
- let validCells = [];
- let totalWater = Number(water);
- let totalFire = 0;
- let effort = 0;
- for (let [fireType, fireValue] of fireCells) {
- fireValue = Number(fireValue);
- if (
- ((fireType === 'High' && fireValue >= 81 && fireValue <= 125 && totalWater - fireValue >= 0) ||
- (fireType === 'Medium' && fireValue >= 51 && fireValue <= 80 && totalWater - fireValue >= 0) ||
- (fireType === 'Low' && fireValue >= 1 && fireValue <= 50 && totalWater - fireValue >= 0))) {
- validCells.push(fireValue);
- totalWater -= fireValue;
- totalFire += fireValue;
- effort += fireValue * 0.25;
- }
- }
- console.log('Cells:');
- for(let cell of validCells){
- console.log(` - ${cell}`);
- }
- console.log(`Effort: ${effort.toFixed(2)}`);
- console.log(`Total Fire: ${totalFire}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement