matrix - Finding the optimum column and row size for a table with n elements and a given range for its proportion -
I am looking for an optimal way of creating tables from n elements so that there is no empty cell, but at the same time the table dimensions The ratio of columns / rows probably gets closer to 1.
Of course, n is a square number, since then it is easy
cols = rows = sqrt (n); If n is a major number then it is also clear that there will be empty cells, so it's about handling my current way:
line = Floor (Sqrt (n)); Cols = seat (n / rows); For all other cases, I plan to get the main factors of N and after that, all the possible passages for all those people whose ratio is close to 1 .
The question is: Is there a better way to do this? Or there is at least one way that is not testing every possible combination of key factors?
Instead of creating a key component of n , start with square root and Next big (or small - it does not matter) Find factor: The pair of factors will be closest to the square root, and therefore the closest in the ratio 1: 1.
Comments
Post a Comment