MathGroup Archive 2002

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

Search the Archive

Re: Rolling up some integers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33454] Re: [mg33404] Rolling up some integers
  • From: gleam at flashmail.com (Paul)
  • Date: Thu, 21 Mar 2002 09:28:52 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Mark,

Here is the code I arrived at:

wrapsquarematrix[lst_List, x_Integer] /; Length[lst] >= x^2 :=
  Module[{a, n = 0},
    a = Table[0, {x}, {x}];
    Do[a[[i, j - i + 1]] = 
        lst[[++n]], {j, 1, x}, {i, 1, 
        j}];
    Do[a[[i + j, x - i + 1]] = 
        lst[[++n]], {j, 1, x - 1}, {i, 1,
         x - j}];
    a
    ]

It is "non-snaking" per your definision.  If it wraps the "wrong" way,
just use Transpose.  If you want a more robust function that can
produce rectangular matricies, let me know.

Paul



  • Prev by Date: Vector Diagrams
  • Next by Date: Re: NextComposition - the bug?
  • Previous by thread: Re: Rolling up some integers
  • Next by thread: RE: Rolling up some integers