Rolling up some integers

Wouter Meeussen wouter.meeussen at pandora.be
Sun Mar 24 20:05:16 CET 2002


Ah,
then maybe
Table[(i+j-1)((i+j-1)-1)/2+1+(j-1)-Mod[i+j-1 ,n,1]^2
Quotient[i+j-1,n,1],{i,n},{j,n}]//MatrixForm

grin, grin,

Wouter.

----- Original Message -----
From: "Michael Somos" <somos at grail.cba.csuohio.edu>
To: <seqfan at ext.jussieu.fr>
Cc: <wouter.meeussen at pandora.be>
Sent: Sunday, March 24, 2002 8:00 PM
Subject: Re: Rolling up some integers


> Seqfans,
>
> Wouter Meeussen wrote :
>
> > Ken Levasseur replied with an elegant permutation technique that can be
> > thrown into the following one-liner:
>
> >
flatindex[n_]:=Ordering[Sort[Flatten[Outer[List,Range[n],Range[n]],1]//Rever
> > se,Plus@@#1<=Plus@@#2&]/. {i_Integer,j_}->n(i-1)+j]
>
> I think this is a bit more than one line and Mathematica encourages
> baroque programming practices. However, I have better PARI-GP code :
>
> ? U(n,i,j) = 1-i+if(i+j<=n,binomial(i+j,2),n^2+n-binomial(2*(n+1)-i-j,2))
> ? print(matrix(4,4,i,j,U(4,i,j)))
> [1, 3, 6, 10; 2, 5, 9, 13; 4, 8, 12, 15; 7, 11, 14, 16]
>
> Shalom, Michael
>






More information about the SeqFan mailing list