Re: ZigZag matrix rearrange

• To: mathgroup at smc.vnet.net
• Subject: [mg99187] Re: ZigZag matrix rearrange
• From: Ray Koopman <koopman at sfu.ca>
• Date: Wed, 29 Apr 2009 06:38:08 -0400 (EDT)
• References: <200904250851.EAA14256@smc.vnet.net> <gt3f07\$i8p\$1@smc.vnet.net>

```If the second element of the output is supposed to be the {1,2}
element of the input then the reversal test needs to be changed:

zz[m_] := With[{n = Length@m}, Flatten@Table[
If[OddQ[n+k],#,Reverse@#]&@Diagonal[Reverse@m,k],{k,1-n,n-1}]]

Array[10#1+#2&,{4,4}]
zz@%

{{11,12,13,14},
{21,22,23,24},
{31,32,33,34},
{41,42,43,44}}

{11,
12,21,
31,22,13,
14,23,32,41,
42,33,24,
34,43,
44}

Array[10#1+#2&,{5,5}]
zz@%

{{11,12,13,14,15},
{21,22,23,24,25},
{31,32,33,34,35},
{41,42,43,44,45},
{51,52,53,54,55}}

{11,
12,21,
31,22,13,
14,23,32,41,
51,42,33,24,15,
25,34,43,52,
53,44,35,
45,54,
55}

On Apr 26, 10:14 pm, DrMajorBob <btre... at austin.rr.com> wrote:
> Far simpler is:
>
> Clear[m]
> m=Array[{##}&,{8,8}]
> (t1=Table[If[OddQ@k,Reverse@#,#]&@Diagonal[Reverse@m,k],
> {k,-7,7}])//Column
> {{{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8}},
>  {{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8}},
>  {{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8}},
>  {{4,1},{4,2},{4,3},{4,4},{4,5},{4,6},{4,7},{4,8}},
>  {{5,1},{5,2},{5,3},{5,4},{5,5},{5,6},{5,7},{5,8}},
>  {{6,1},{6,2},{6,3},{6,4},{6,5},{6,6},{6,7},{6,8}},
>  {{7,1},{7,2},{7,3},{7,4},{7,5},{7,6},{7,7},{7,8}},
>  {{8,1},{8,2},{8,3},{8,4},{8,5},{8,6},{8,7},{8,8}}}
> {{1,1}}
> {{2,1},{1,2}}
> {{1,3},{2,2},{3,1}}
> {{4,1},{3,2},{2,3},{1,4}}
> {{1,5},{2,4},{3,3},{4,2},{5,1}}
> {{6,1},{5,2},{4,3},{3,4},{2,5},{1,6}}
> {{1,7},{2,6},{3,5},{4,4},{5,3},{6,2},{7,1}}
> {{8,1},{7,2},{6,3},{5,4},{4,5},{3,6},{2,7},{1,8}}
> {{2,8},{3,7},{4,6},{5,5},{6,4},{7,3},{8,2}}
> {{8,3},{7,4},{6,5},{5,6},{4,7},{3,8}}
> {{4,8},{5,7},{6,6},{7,5},{8,4}}
> {{8,5},{7,6},{6,7},{5,8}}
> {{6,8},{7,7},{8,6}}
> {{8,7},{7,8}}
> {{8,8}}
>
> or
>
> Flatten[t1,1]//InputForm
> {{1, 1}, {2, 1}, {1, 2}, {1, 3}, {2, 2}, {3, 1},
>   {4, 1}, {3, 2}, {2, 3}, {1, 4}, {1, 5}, {2, 4},
>   {3, 3}, {4, 2}, {5, 1}, {6, 1}, {5, 2}, {4, 3},
>   {3, 4}, {2, 5}, {1, 6}, {1, 7}, {2, 6}, {3, 5},
>   {4, 4}, {5, 3}, {6, 2}, {7, 1}, {8, 1}, {7, 2},
>   {6, 3}, {5, 4}, {4, 5}, {3, 6}, {2, 7}, {1, 8},
>   {2, 8}, {3, 7}, {4, 6}, {5, 5}, {6, 4}, {7, 3},
>   {8, 2}, {8, 3}, {7, 4}, {6, 5}, {5, 6}, {4, 7},
>   {3, 8}, {4, 8}, {5, 7}, {6, 6}, {7, 5}, {8, 4},
>   {8, 5}, {7, 6}, {6, 7}, {5, 8}, {6, 8}, {7, 7},
>   {8, 6}, {8, 7}, {7, 8}, {8, 8}}
>
> Bobby

```

• Prev by Date: Re: issues with GraphPlot
• Next by Date: Re: Mathematica crashed -- where did my notebook go?
• Previous by thread: Re: Re: ZigZag matrix rearrange
• Next by thread: Re: ZigZag matrix rearrange