Number of circles packed into a rectangle [closed]

Calculate the maximum number of circles of radius r that can fit in a rectangle with width x and height y. Write a function that take r, x and y as input and returns the number of circles that fit in the rectangle.

• I would suggest to add some testcases so that we can know if any answer is correct.
– tsh
Nov 3, 2018 at 15:44
• It appears to me that one could fit at least one more circle, by expanding the second-to-last row to have 10 circles in it, such that the last three rows touch each other orthogonally. Do we not have to handle such cases? Nov 3, 2018 at 15:56
• Would it make sense to just normalise and say r is always 1? This way there are only 2 inputs - I believe every answer will divide through by r. Nov 3, 2018 at 15:58
• Do we have to support floats or are x,y,r guaranteed to be whole numbers? Nov 3, 2018 at 16:34
• Without the "triangular lattice" restriction we have math.stackexchange.com/questions/701/… , which is unsolved. Nov 3, 2018 at 16:45