Re: rules on vector sequence

• To: mathgroup at smc.vnet.net
• Subject: [mg98081] Re: rules on vector sequence
• From: Ray Koopman <koopman at sfu.ca>
• Date: Sun, 29 Mar 2009 02:48:35 -0500 (EST)
• References: <gqkurj\$47q\$1@smc.vnet.net>

```On Mar 28, 3:40 am, Filippo Miatto <sottosupr... at gmail.com> wrote:
> Dear all,
> I need to generate all the vectors, of a given length N, that have
> these three properties:
>
> 1- the entries have to be among -2,-1,0,1,2
> 2- the sum of all the entries has to be 0
> 3- only two or four of the entries can be different from 0
>
> do you have any suggestions on how i can do that? i tried something
> but without success.. expecially i don't know how to implement the
> third rule..
> Filippo

Treat the third rule as defining two separate problems.

s = Join[Union[Sort/@Select[Tuples[{-2,-1,1,2},2],Tr@#==0&]],
Union[Sort/@Select[Tuples[{-2,-1,1,2},4],Tr@#==0&]]]

{{-2,2},{-1,1},{-2,-2,2,2},{-2,-1,1,2},{-1,-1,1,1}}

Then pad each sublist out to the desired length
and get all its permutations.

{{0, 0, -2, 2}, {0, 0, 2, -2}, {0, -2, 0, 2}, {0, -2, 2, 0},
{0, 2, 0, -2}, {0, 2, -2, 0}, {-2, 0, 0, 2}, {-2, 0, 2, 0},
{-2, 2, 0, 0}, {2, 0, 0, -2}, {2, 0, -2, 0}, {2, -2, 0, 0},
{0, 0, -1, 1}, {0, 0, 1, -1}, {0, -1, 0, 1}, {0, -1, 1, 0},
{0, 1, 0, -1}, {0, 1, -1, 0}, {-1, 0, 0, 1}, {-1, 0, 1, 0},
{-1, 1, 0, 0}, {1, 0, 0, -1}, {1, 0, -1, 0}, {1, -1, 0, 0},
{-2, -2, 2, 2}, {-2, 2, -2, 2}, {-2, 2, 2, -2}, {2, -2, -2, 2},
{2, -2, 2, -2}, {2, 2, -2, -2}, {-2, -1, 1, 2}, {-2, -1, 2, 1},
{-2, 1, -1, 2}, {-2, 1, 2, -1}, {-2, 2, -1, 1}, {-2, 2, 1, -1},
{-1, -2, 1, 2}, {-1, -2, 2, 1}, {-1, 1, -2, 2}, {-1, 1, 2, -2},
{-1, 2, -2, 1}, {-1, 2, 1, -2}, {1, -2, -1, 2}, {1, -2, 2, -1},
{1, -1, -2, 2}, {1, -1, 2, -2}, {1, 2, -2, -1}, {1, 2, -1, -2},
{2, -2, -1, 1}, {2, -2, 1, -1}, {2, -1, -2, 1}, {2, -1, 1, -2},
{2, 1, -2, -1}, {2, 1, -1, -2}, {-1, -1, 1, 1}, {-1, 1, -1, 1},
{-1, 1, 1, -1}, {1, -1, -1, 1}, {1, -1, 1, -1}, {1, 1, -1, -1}}

```

• Prev by Date: Re: rules on vector sequence
• Next by Date: Re: pdf export problem
• Previous by thread: Re: rules on vector sequence
• Next by thread: Re: rules on vector sequence