# Calculate width in a grid with lines

This is a web related question but is a mathematical problem.

Look at this:

|O|O|O|O|

|O|O|O|

|O|O|

• A vertical line represents a 1 pixel wide horizontal line.
• A 'O' represents a space between the lines.
• All the three rows should have the same width. The space 'O' is streched out to fill the space equally within the row to fill it up. (The last row will get more space than the first.)
• The space width can't contain decimals.
• I want to find the perfect width for all three lines between 960 and 1140 pixels wide.

Questions

1. What is the row width?
2. How did you calculate it?

What I know so far

• First line have 5 pixels of lines, the second 4 pixels and the third 3 pixels.
• 960 and 1140 are perfect numbers because they can be divided by 3, 4 and 2, but this case includes borders which makes it tricky.
-

Let the width be $n$. You want $n-5$ to be a multiple of 4, $n-4$ a multiple of 3, and $n-3$ a multiple of 2. This is the same as asking for $n-1$ to be a multiple of 12, so you can take $n$ to be any of the numbers 961, 973, 985, ..., 1129.

-
Good answer. I have checked the numbers and they work. I might even need a row with 5. Is that hard to calculate? In this case it's 960 + 1 + 12, in short. Is there a "magic" number when adding 5 in a row? n - 1 = ? –  Jens Törnell Aug 17 '12 at 19:05
Well let the width of the space be n pixels, and $a$, $b$ and $c$ the widths of "O" in the three cases. You need to solve the three equations: $$4a+5=n=4(a+1)+1$$ $$3b+4=n=3(b+1)+1$$ $$2c+3=n=2(c+1)+1$$ So you need $n$ to be 1 more than a multiple of 2,3, and 4 - so $n=12r+1$ will work for any $r$ with $a+1=3r; b+1=4r; c+1=6r$ - which gives you plenty of options to work with.