Return how many integer grid points there are inside a circle of radius r centred at (0,0) (including points on the edge).
Neither string operations nor interpolations are allowed!
I think there is an error with the r = 7.5 test case. By the definition of the problem, it should be 177, not 172. The working solutions use a mesh that is not on integer grid points.
I also got 177 for r=7.5 as well using (the cody unfriendly) two for loops.
@Michael_C. and @James, Thank you! I have indeed overlooked that edge case. The problem is now fixed. (The "for" loops are unnecessary).
Yaroslav, you are certainly correct that for loops are not needed. I just used them to confirm that my answer using the "no-for-loop-required algorithm" was correct before commenting on the problem. My similar problem (Cody problem 1387) only used integer radii.
Thanks for the correction!
Times 2 - START HERE
Return unique values without sorting
Get the length of a given vector
Remove from a 2-D matrix all the rows that contain at least one element less than or equal to 4
Derivative of polynomial
Edges of a n-dimensional Hypercube
Dots in a Diamond
Dots in a Sphere
Volume of a Simplex
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office