How many columns in a grid of arbitrary width, with minimum and maximum allowed column widths?

179 Views Asked by At

In a grid of variable width, with a variable number of columns having a minimum and maximum allowed width, how can I calculate the number of columns for any given grid width so they fall within the minimum and maximum allowed column width?

Phrased differently, if I have a magical shrinking chess board, and each tile on the board must be between 2cm-3cm wide, is it possible to calculate how many tiles are allowed in each row so that each tile falls between the minimum and maximum allowed widths as the board shrinks?

Sorry if this is a ridiculous question, I am a UI developer with no maths background. :)

1

There are 1 best solutions below

0
On BEST ANSWER

It is not a ridiculous question, but maybe not well stated. If your input is the w=width and mnc=minimum column width, mxc=maximum column width, the minimum number of tiles is $\frac w{mxc}$ rounded up to the next whole number. The maximum number of tiles is $\frac w{mnc}$ rounded down. This works if the tiles can be any rational width. If they need to be integral, it is harder. Is that what you were looking for?