Comments on How many umbrellas to cover the beach?
Post
How many umbrellas to cover the beach?
You work at a beach. In the afternoon, the sun gets quite hot and beachgoers want to be shaded. So you put out umbrellas. When you put out umbrellas you want to shade the entire beach, with as few umbrellas as possible.
Umbrellas come in many sizes. However, larger umbrellas are susceptible to being pulled away by the wind, so in the morning you have to go to the beach and do a soil test. The soil test tells you, for each spot on the beach, the size of the largest umbrella that could be safely placed.
So after your soil test, you get back a list of positive integers. For example:
[2,1,3,1,3,1,1,2,1]
Each number represents the maximum radius of an umbrella that can be placed at that location. A radius $r$ umbrella covers itself, and $r-1$ spots to both its left and right.
For example a radius 3 umbrella covers:
- itself
- the two spaces directly adjacent to it,
- the two further spaces adjacent to those,
Your task is to write a computer program which takes the results of the soil test as a list of positive integers, and gives back the minimum number of umbrellas required to cover all the spots on the beach.
For example if the soil test gives back [2,1,4,1,4,1,1,3,1]
, then you can cover the beach with 2 umbrellas:
X X X X X
X X X X X X X |
| |
[_,_,4,_,_,_,_,3,_]
So the output of the program should be 2.
This is code-golf so the goal is to minimize the size of your source code as measured in bytes.
Test cases
[9,2,1,3,2,4,2,1] -> 1
[1,1,1,1,1,1,1,1] -> 8
[2,1,4,1,4,1,1,3,1] -> 2
[5,1,3,1,3,1,1,1,6] -> 2
1 comment thread