Advertisement
t_sh0w

02. Seize The Fire

Feb 28th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input = []) {
  2.   let cells = input.shift().split("#");
  3.   let water = Number(input.shift());
  4.   let totalEffort = 0;
  5.   let distinguishedCells = [];
  6.   let totalDistinguishedFire = 0;
  7.  
  8.   for (const currentCell of cells) {
  9.     let tokens = currentCell.split(" = ");
  10.     let typeOfFire = tokens[0];
  11.     let valueOfCell = Number(tokens[1]);
  12.  
  13.     switch (typeOfFire) {
  14.       case "High":
  15.         if (water >= valueOfCell && 81 <= valueOfCell && valueOfCell <= 125) {
  16.           water -= valueOfCell;
  17.           totalEffort += valueOfCell * 0.25;
  18.           distinguishedCells.push(valueOfCell);
  19.           totalDistinguishedFire += valueOfCell;
  20.         }
  21.         break;
  22.  
  23.       case "Medium":
  24.         if (water >= valueOfCell && 51 <= valueOfCell && valueOfCell <= 80) {
  25.           water -= valueOfCell;
  26.           totalEffort += valueOfCell * 0.25;
  27.           distinguishedCells.push(valueOfCell);
  28.           totalDistinguishedFire += valueOfCell;
  29.         }
  30.         break;
  31.  
  32.       case "Low":
  33.         if (water >= valueOfCell && 1 <= valueOfCell && valueOfCell <= 50) {
  34.           water -= valueOfCell;
  35.           totalEffort += valueOfCell * 0.25;
  36.           distinguishedCells.push(valueOfCell);
  37.           totalDistinguishedFire += valueOfCell;
  38.         }
  39.         break;
  40.     }
  41.   }
  42.   console.log(`Cells:`);
  43.   for (const cell of distinguishedCells) {
  44.     console.log(`- ${cell}`);
  45.   }
  46.   console.log(`Effort: ${totalEffort.toFixed(2)}`);
  47.   console.log(`Total Fire: ${totalDistinguishedFire}`);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement