Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6617

Re: Loop problem

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Loop problem
Date 2011-11-22 10:41 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jafu8a$rqj$1@smc.vnet.net> (permalink)

Show all headers | View raw


On 11/21/11 at 4:27 AM, puya.sharif@live.com (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

Permutations[{0,1,2,3}]

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.

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Loop problem Bill Rowe <readnews@sbcglobal.net> - 2011-11-22 10:41 +0000

csiph-web