# 1040 grid, 3 boxed, what space?

A grid

I have a grid with boxes. The total grid is 1040 wide.

Number of boxes and spaces

I have 3 boxes an 2 spaces between them.

Question

What are the number of pixels between the boxes, the spaces? I want to come as close to space number 15 as possible. The problem I have is that the sum is never exact 1040.

The space don't have to be 15 but every box needs to be equal in width.

|Box1|Space|Box2|Space|Box3|

I tried to set the space to 15 but ( 1040 - ( 15 x 2 ) ) / 3 = 336,667

I want the box to be a whole number like 336. The number of 15 can change close to it up or down.

• You'll have to make a compromise somewhere for the reason you described. One space could 15 and the other 14. However, since you are dealing with integers, there are some combinations that just are not possible. Feb 21 '14 at 15:41
• I forgot to write that every box has to be equal in size. Some formula may calculate if there are space numbers that would make it? And the answer might be like 3, 5, 18, 25. Feb 21 '14 at 15:47
• Do you mean that the spaces have to be equal width too? Feb 21 '14 at 15:53
• Yes. It's impossible? Feb 21 '14 at 16:01

If $b$ is the width of a box and $s$ the width of the space between them, then your requirements can be expressed as follows:

$$3b + 2s = 1040 \Rightarrow s = {{1040-3b}\over{2}} = 520 - {3 \over 2} b$$

To make $s$ an integer requires that ${3 \over 2 } b$ be an integer. Thus, $b = 2k$, for $k=1,2,\dots$, and the possible values of $s$ and $b$ will be

$$\begin{array}{rcl} b & = & 2k \\ s & = & 520 - 3k \end{array}$$

for integers $k < 520/3$.

As an example, for $k = 168$, we have that $s=16$ and $b=336$, which gives

$$3 \cdot 336 + 2 \cdot 16 = 1040.$$