← Back to challenges

Count the Points in a Circle

PythonHardmatharrays

Instructions

Count the total number of coordinates on a two-dimensional grid that are inside a given circle. The function has four parameters: the points (provided as a list of dictionaries), the circle's center x coordinate, the circle's center y coordinate, and the circle's radius.

Examples

points_in_circle([
  { "x": 0, "y": 0 },
  { "x": 1, "y": 1 },
  { "x": 0, "y": 5 },
  { "x": 10, "y": 10 }
], 0, 0, 5) ➞ 2

Notes

Only count the coordinates that are in the circle, not the ones that are on the border.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.