Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on How many umbrellas to cover the beach?

Post

How many umbrellas to cover the beach?

+3
−0

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
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Inconsistent meaning of radius (2 comments)
Inconsistent meaning of radius

Skipping 1 deleted comment.

WheatWizard‭ wrote 7 months ago

Fixed. Not sure what the point of sandboxing is on a site which only has 3-4 active users.

trichoplax‭ wrote 7 months ago

Same point, just smaller probabilities. Only a suggestion - it's your call.