Beta
Planting carrots
Description:
Planting carrots
Old MacDonald had a farm, E-I-E-I-O.
And on that farm he had a cow, E-I-E-I-O.
With a moo moo here and a moo moo there
Here a moo, there a moo, everywhere a moo moo
Old MacDonald had a farm, E-I-E-I-O.
The farmer loves carrots, unfortunately evil rabbits still steal them!
MacDonald decided to surround a fragment of his garden with the fence where he will be able to safely plant his favorite vegetables.
Because the farmer was a mathematician, he plants carrots only in places with integer coordinates also the fence is made of straight sections hooked at points with integer coordinates.
Given coordinates of fence, help the farmer count how many carrots he can plant in his garden!
Example
![]() |
In this example, fence is build of 5 segments and surrounds area with 23 possible carrots positions.
|
Task
Complete the function count_carrots
which receive fence coordinates as only arguments and
should return maximum number of carrots thet farmer can plant.
Notes
- Surrounded area is a simple polygon.
- Fence has at least 3 vertices and at most 1000. Coordinates are bounded by -106 <= x,y <= 106.
Algorithms
Mathematics
Geometry
Similar Kata:
Stats:
Created | Jan 21, 2018 |
Published | Jan 21, 2018 |
Warriors Trained | 66 |
Total Skips | 15 |
Total Code Submissions | 39 |
Total Times Completed | 7 |
Ruby Completions | 7 |
Total Stars | 3 |
% of votes with a positive feedback rating | 67% of 6 |
Total "Very Satisfied" Votes | 3 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |