Your question is Sheep in a Ring Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
A diagnostic utility for Nordic Semiconductor's nRF Connect SDK receives sheep positions relative to a circular fenced area. Given the sheep coordinates, the fence center, and its radius, return how many sheep are inside or exactly on the boundary.
Use Euclidean distance. A sheep is inside when its squared distance from the center is less than or equal to the squared radius.
Implement count_sheep_inside(sheep, center, radius).
sheep is a list of two-element integer lists, where each list is [x, y].center is a two-element integer list [x, y].radius is a non-negative integer.Do not use square roots. Comparing squared distances is sufficient and avoids unnecessary floating-point operations.
def count_sheep_inside(sheep, center, radius):