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.



closed as unclear what you're asking by user202729, Jonathan Allan, Erik the Outgolfer, mbomb007, manatwork Nov 3 '18 at 17:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 12
    \$\begingroup\$ I would suggest to add some testcases so that we can know if any answer is correct. \$\endgroup\$ – tsh Nov 3 '18 at 15:44
  • 5
    \$\begingroup\$ 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? \$\endgroup\$ – ETHproductions Nov 3 '18 at 15:56
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Allan Nov 3 '18 at 15:58
  • 2
    \$\begingroup\$ Do we have to support floats or are x,y,r guaranteed to be whole numbers? \$\endgroup\$ – Black Owl Kai Nov 3 '18 at 16:34
  • 2
    \$\begingroup\$ Without the "triangular lattice" restriction we have math.stackexchange.com/questions/701/… , which is unsolved. \$\endgroup\$ – user202729 Nov 3 '18 at 16:45