I have n
elements as a input and a function make_grid(n)
which will calculate the dimensions of a grid that will contain the elements. Let's suppose that n = 12
, then the function must calculate that the width is 4 and the height is 3 and not 1 and 12 or so. Similarly, n = 24
should return 6 and 4.
I tried to use ceil(sqrt(n))
to get one dimension, but is not a general case at all, and playing with cases (n even, sqrt(n) == ceil(sqrt(n))
) hasn't worked.
Edit: Finding the optimum column and row size for a table with n elements and a given range for its proportion I already see this question but the coding throws me for n = 24 dimensions 5 and 5. Any help?