Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: ZigZag matrix rearrange

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99074] Re: ZigZag matrix rearrange
  • From: ADL <alberto.dilullo at tiscali.it>
  • Date: Sun, 26 Apr 2009 01:38:28 -0400 (EDT)
  • References: <gsuit1$dsc$1@smc.vnet.net>

Probably you will receive several beautiful one-liners.
Anyway, my rough solution is:

plist[n_] :=Module[
  {lip, ulip},
  Table[
    lip = Rest@IntegerPartitions[i + 1, 2];
    ulip = Union@Join[lip, Reverse /@ lip];
    If[EvenQ[i], ulip, Reverse[ulip]],
        {i, 2 n - 1}
    ] /. {a_, b_} /; Max[a, b] > n :> Sequence[]
  ];

Apply[t[[##]] &, plist[8], {2}]     produces your pattern with sublist

Apply[t[[##]] &, Flatten[plist[8], 1], {1}]     produces your pattern
as a flat list

By changing the parameter n in plist you can create bigger/smaller
patterns.

ADL


On 25 Apr, 10:50, "Serych Jakub" <Ser... at panska.cz> wrote:
> Dear community,
> I'm trying to rearrange 8 x 8 matrix of numbers in ZigZag manner (as it is
> used in JPEG comprimation algorithmhttp://en.wikipedia.org/wiki/Jpeg).
>
> I have created function which does it without problems, but it does it "by
> hand" and it seems to me, that it could be done by some more elegant
> algorithm.
> Does somebody have any idea, how to do it more elegantly?
> ...
> Thanks for any idea
>
> Jakub



  • Prev by Date: Re: Replace elements in structured list
  • Next by Date: Re: ContourPlot, equation and R.H. side of
  • Previous by thread: Re: ZigZag matrix rearrange
  • Next by thread: Re: ZigZag matrix rearrange