DEV Community

Discussion on: Daily Challenge #274 - Aerial Firefighting

Collapse
 
peter279k profile image
peter279k • Edited

Here is the simple solution with Python and it uses math.ceil, a for loop and a string splitting:

import math
def waterbombs(fire, w):
    fire_arr = fire.split('Y')
    counter = 0;

    for fire_x in fire_arr:
        counter += math.ceil(len(fire_x) / w)

    return counter
Collapse
 
vinaypai profile image
Vinay Pai

You can use the built-in sum function to simplify your solution.

import math
def waterbombs(fire, w):
  return sum(math.ceil(len(fr) / w) for fr in fire.split('Y'))
Collapse
 
peter279k profile image
peter279k

Thanks for your simplify code snippets.

But I want to make my code snippets readable :).