MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Rolling up some integers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33455] Re: [mg33404] Rolling up some integers
  • From: Ken Levasseur <Kenneth_Levasseur at uml.edu>
  • Date: Thu, 21 Mar 2002 09:28:57 -0500 (EST)
  • References: <200203200653.BAA07992@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mark:

Here is a non-snaking solution, but it looks sort of like what you describe.

In[1]:=
data[n_] := Range[n^2]

In[2]:=
order[n_] := Sort[Flatten[Outer[List, Range[n], Range[n]], 1], Plus @@ #1 <=
Plus @@ #2 & ];

In[3]:=
Transpose[{order[4],data[4]}]//Sort[#,(First[First[#1]]?First[First[#2]])&]&//Transpose//Last//Partition[#,4]&

Out[3]=
{{1, 2, 4, 7}, {3, 5, 8, 11}, {6, 9, 12, 14},

  {10, 13, 15, 16}}

Ken Levasseur
UMass Lowell


"DIAMOND Mark R." wrote:

> Can anyone see an easy way of  putting a fiven list of n^2 integers into an
> n*n matrix along the diagonals---could be either not-snaking (preferred)
> snaking. The *ordering*, but not necessarily the integers themselves, would
> be
>
> 1 3 6
> 2 5 8
> 4 7 9
>
> I would call this non-snaking, or  the following, snaking.
>
> 1 2 6
> 3 5 7
> 4 8 9
>
> Please note,.
>
> It occurred to me that this might be possible by first partitioning into
> ascending and descending size lists representing each diagonal, but aside
> from constructing an explicit secondary matrix of indices, I can't see
> another way of doing it.
>
> Cheers,
>
> Mark
> --
> Mark R. Diamond
> No spam email ROT13: znexq at cfl.hjn.rqh.nh
> No crawler web page ROT13 uggc://jjj.cfl.hjn.rqh.nh/hfre/znexq



  • Prev by Date: Re: Export Directory
  • Next by Date: Re: newbie question - printing Pi
  • Previous by thread: Rolling up some integers
  • Next by thread: Re: Rolling up some integers