# [R] make matrices as many as possible with a constraint

David Winsemius dwinsemius at comcast.net
Fri Dec 12 02:13:56 CET 2014

```On Dec 11, 2014, at 4:38 PM, Kathryn Lord wrote:

> Dear R users,
>
> I'd like to make 4 by 7 matrices as many as possible with natural numbers 1
> through 28 such that each matrix have different elements of each column.

I was tempted to respond:

We're very sorry. The Soduko Challenge Contest was closed several years ago.

>
> For example,
>
> simply here is one
>
>> a1 <- matrix(1:28, 4,7)
>> a1
>     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> [1,]    1    5    9   13   17   21   25
> [2,]    2    6   10   14   18   22   26
> [3,]    3    7   11   15   19   23   27
> [4,]    4    8   12   16   20   24   28
>
> another one
>
>> a2 <- matrix(1:28, 4,7, byrow=T)
>> a2
>     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> [1,]    1    2    3    4    5    6    7
> [2,]    8    9   10   11   12   13   14
> [3,]   15   16   17   18   19   20   21
> [4,]   22   23   24   25   26   27   28

replicate(1000, list(matrix(sample(28), 4,7) ) )

Somebody ( but not me) will probably know the probability that "each matrix has different elements of each column" once you explain exactly what that phrase means to you. At the moment its not clear if a permutation of columns makes a matrix "different".

>
> Matrices a1 and a2 have different columns, and I guess there are such many
> matrices.
>
> Any suggestion will be greatly appreciated.
>
> Best,
>
> Kathryn Lord
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help