MathGroup Archive 2011

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

Search the Archive

Re: Loop problem

  • To: mathgroup at
  • Subject: [mg123064] Re: Loop problem
  • From: Bill Rowe <readnews at>
  • Date: Tue, 22 Nov 2011 05:35:15 -0500 (EST)
  • Delivered-to:

On 11/21/11 at 4:27 AM, puya.sharif at (P Shar) wrote:

>Hey guys, i need a loop (that does the following) and can't figure
>out what to do..

>I need a set of lists {i,j,k,l} i=E2=89 j=E2=89 k=E2=89 l, i=E2=89=
 j=k=E2=89 l, i=E2=89 j=E2=89 k=l, i=E2=89 k=E2=89 j=l
>where 0 < i,j,k,l < 3.

>So basically all the cases where the first condition holds and all
>the cases there the second holds etc..

>Easiest would be to get the output as a matrix with the {i,j,k,l}'s
>as rows.

>Any ideas (or at least where to start)?

First, I assume the range for i,j,k,l is {0,1,2,3} i.e., you
meant less than or equal rather than strictly less than. If you
did mean strictly less than, then your conditions lead to a null
set for all cases. There are only two integers between 0 and 3
and you require a minimum of 3 distinct integers.

So with that, the first case (all four distinct) is done by


The remaining conditions can all be achieve with variations of:

Cases[Tuples[{0, 1, 2, 3}, 3], _?(Length@Union[#] == 3 &)] /.
{a_, b_,
     c_} -> {a, b, b, c}

Here, I use Tuples to generate all possible {i,j,k} with each
 >=0 and <=3
Cases to select only those with distinct values and a
replacement rule to insert a copy of one in the right position.

No explicit loops needed.

  • Prev by Date: Re: Help: Regular expressions
  • Next by Date: Re: Matrices as operators
  • Previous by thread: Re: Loop problem
  • Next by thread: Help: Regular expressions