Equally distributing cards on a table. (interpolation)

57 Views Asked by At

this problem is originally from a programming task I am on.

there is a number of playing cards n. the width of each card is w.

now the cards should be placed next to each other on a table with equal space. the table's width is also limited, let's call this t. so t is the available width that should be used by the cards.

now I am looking for a spacing-distance that should be put between each card depending on the above variables. cards can overlap.

so far i simply tried to interpolate depending on the number of cards, but it doesn't work out very well. i think i am missing to take the card width into account, but i don't know how.

1

There are 1 best solutions below

4
On BEST ANSWER

Let the distance between the centers of adjacent cards be $x$. Then $(n-1)x+w=t$, so $x=(t-w)/(n-1)$. That tells you how far apart to put (the centers of) adjacent cards.