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.
  count_carrots([[0, 0], [6, 2], [7, -1], [4, -4], [1, -3]]) == 23

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

More By Author:

Check out these other kata created by pkubiak

Stats:

CreatedJan 21, 2018
PublishedJan 21, 2018
Warriors Trained66
Total Skips15
Total Code Submissions39
Total Times Completed7
Ruby Completions7
Total Stars3
% of votes with a positive feedback rating67% of 6
Total "Very Satisfied" Votes3
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • pkubiak Avatar
Ad