Generating a perfectly distributed grid from array

Posted by zath on Stack Overflow See other posts from Stack Overflow or by zath
Published on 2010-06-16T21:42:04Z Indexed on 2010/06/16 21:42 UTC
Read the original article Hit count: 142

Filed under:
|
|

I'm looking for a formula or rule that will allow me to distribute n characters into a n*n grid with as perfect of a distribution as possible. Let's say we have an array of 5 characters, A through E. Here's an example of how it definitely shouldn't turn out:

A B C D E
B C D E A
C D E A B
D E A B C
E A B C D

The pattern is very clear here, it doesn't look "random". It would look better this way:

A B C D E
D E A B C
B C D E A
E A B C D
C D E A B

What I basically did here was place the A B C D E on the first row, then shift it by 2 on the second row, by 4 on the third row, 1 on the fourth row and 3 on the fifth row.

Compared to the very bad example, this one shows no clear pattern. Though I'm certainly hoping there is a pattern, so I can use it to calculate not only small arrays such as this one, but arrays of any size. Any ideas as to how this can be accomplished?

© Stack Overflow or respective owner

Related posts about array

Related posts about grid