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

Look at this:




  • 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.


  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.

  • $\begingroup$ 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 = ? $\endgroup$ 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.

  • $\begingroup$ Thanks for the answer. n = 12r + 1 works, I checked. In some cases I might even need 5 in a row. Hard to calculate a formula for that as well? $\endgroup$ Aug 18 '12 at 15:49
  • $\begingroup$ Then you should have 60r+1, which will work for 6 too. $\endgroup$ Aug 18 '12 at 16:04
  • $\begingroup$ Thanks! That worked! For some reason I can't give you a vote up. Maybe I'm too new in this Q&A. $\endgroup$ Aug 19 '12 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.