SHARE
TWEET

Untitled

nikolayneykov Mar 23rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve([fire, water]) {
  2.     let fireCells = fire.split('#').map(x => x.split(' = '));
  3.     let validCells = [];
  4.     let totalWater = Number(water);
  5.     let totalFire = 0;
  6.     let effort = 0;
  7.  
  8.     for (let [fireType, fireValue] of fireCells) {
  9.         fireValue = Number(fireValue);
  10.         if (
  11.             ((fireType === 'High' && fireValue >= 81 && fireValue <= 125 && totalWater - fireValue >= 0) ||
  12.                 (fireType === 'Medium' && fireValue >= 51 && fireValue <= 80 && totalWater - fireValue >= 0) ||
  13.                 (fireType === 'Low' && fireValue >= 1 && fireValue <= 50 && totalWater - fireValue >= 0))) {
  14.             validCells.push(fireValue);
  15.             totalWater -= fireValue;
  16.             totalFire += fireValue;
  17.             effort += fireValue * 0.25;
  18.         }
  19.     }
  20.  
  21.     console.log('Cells:');
  22.     for(let cell of validCells){
  23.         console.log(` - ${cell}`);
  24.     }
  25.     console.log(`Effort: ${effort.toFixed(2)}`);
  26.     console.log(`Total Fire: ${totalFire}`);
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top