DEV Community

Discussion on: Daily Challenge #274 - Aerial Firefighting

Collapse
 
amarjeet94 profile image
amarjeet singh

It seems to be a simple yet interesting also..
The idea to find the minimum number of waterbombs can be found by :
say Test: waterbombs("xxxxYxYx", 4)
step1 : split first param by 'Y'
step2: set second param as width
step3: find the mod of length of substring by width value
step4: sum up the mod value that is your minimum number of waterbombs

Collapse
 
darthbob88 profile image
Raymond Price • Edited

Step 3 is not quite correct, I think; you'd need to get the ceiling of the width of the string divided by the width of the bomb. ("xxxxx", 2) is 3, since two bombs will take out 4 squares of fire and leave 1 more to mop up.

E: My JS solution

var waterbombs = (fireString, bombWidth) => {
    const fires = fireString.split("Y");
    let bombsNeeded = 0;
    for (let fire in fires) {
        bombsNeeded += Math.ceil(fire.length / bombWidth);
    }
    return bombsNeeded;
}
Collapse
 
amarjeet94 profile image
amarjeet singh

yes, you are right brother

Collapse
 
rafaacioly profile image
Rafael Acioly

Talk is cheap, show me the code ;)