Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input = []) {
- let cells = input.shift().split("#");
- let water = Number(input.shift());
- let totalEffort = 0;
- let distinguishedCells = [];
- let totalDistinguishedFire = 0;
- for (const currentCell of cells) {
- let tokens = currentCell.split(" = ");
- let typeOfFire = tokens[0];
- let valueOfCell = Number(tokens[1]);
- switch (typeOfFire) {
- case "High":
- if (water >= valueOfCell && 81 <= valueOfCell && valueOfCell <= 125) {
- water -= valueOfCell;
- totalEffort += valueOfCell * 0.25;
- distinguishedCells.push(valueOfCell);
- totalDistinguishedFire += valueOfCell;
- }
- break;
- case "Medium":
- if (water >= valueOfCell && 51 <= valueOfCell && valueOfCell <= 80) {
- water -= valueOfCell;
- totalEffort += valueOfCell * 0.25;
- distinguishedCells.push(valueOfCell);
- totalDistinguishedFire += valueOfCell;
- }
- break;
- case "Low":
- if (water >= valueOfCell && 1 <= valueOfCell && valueOfCell <= 50) {
- water -= valueOfCell;
- totalEffort += valueOfCell * 0.25;
- distinguishedCells.push(valueOfCell);
- totalDistinguishedFire += valueOfCell;
- }
- break;
- }
- }
- console.log(`Cells:`);
- for (const cell of distinguishedCells) {
- console.log(`- ${cell}`);
- }
- console.log(`Effort: ${totalEffort.toFixed(2)}`);
- console.log(`Total Fire: ${totalDistinguishedFire}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement