Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: There must be a better way.
Replies: 3   Last Post: Aug 22, 2010 8:14 AM

 Messages: [ Previous | Next ]
 Murta Posts: 86 Registered: 7/5/10
Re: There must be a better way.
Posted: Aug 22, 2010 8:14 AM

On Aug 20, 8:11 am, Ray Koopman <koop...@sfu.ca> wrote:
> On Aug 19, 4:19 am, "S. B. Gray" <stev...@ROADRUNNER.COM> wrote:
>
>
>
>
>

> > pts = 5;
> > angx = Flatten[
> > Table[Join[{j},
> > Subsets[Cases[Range[pts],Except[j]],{2}][[i]]],{j,
> > pts},{i,(pts-1)(pts-2)/2}],1]

>
> > which if pts=4 gives
>
> > {{1, 2, 3}, {1, 2, 4}, {1, 3, 4},
> > {2, 1, 3}, {2, 1, 4}, {2, 3, 4},
> > {3, 1, 2}, {3, 1, 4}, {3, 2, 4},
> > {4, 1, 2}, {4, 1, 3}, {4, 2, 3}}

>
> > and for pts=5 prints:
>
> > {{1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5}, {1, 4, 5},
> > {2, 1, 3}, {2, 1, 4}, {2, 1, 5}, {2, 3, 4}, {2, 3, 5}, {2, 4, 5},
> > {3, 1, 2}, {3, 1, 4}, {3, 1, 5}, {3, 2, 4}, {3, 2, 5}, {3, 4, 5},
> > {4, 1, 2}, {4, 1, 3}, {4, 1, 5}, {4, 2, 3}, {4, 2, 5}, {4, 3, 5},
> > {5, 1, 2}, {5, 1, 3}, {5, 1, 4}, {5, 2, 3}, {5, 2, 4}, {5, 3, 4}}

>
> > and for pts=6 gives
>
> > {{1,2,3},{1,2,4},{1,2,5},{1,2,6},{1,3,4},{1,3,5},{1,3,6},{1,4,5},{1,4,6},{1 ,
> > 5, 6},
> > {2,1,3},{2,1,4},{2,1,5},{2,1,6},{2,3,4},{2,3,5},{2,3,6},{2,4,5},
> > {2,4,6},{2,5,6},
> > {3,1,2},{3,1,4},{3,1,5},{3,1,6},{3,2,4},{3,2,5},{3,2,6},{3,4,5},
> > {3,4,6},{3,5,6},
> > {4,1,2},{4,1,3},{4,1,5},{4,1,6},{4,2,3},{4,2,5},{4,2,6},{4,3,5},
> > {4,3,6},{4,5,6},
> > {5,1,2},{5,1,3},{5,1,4},{5,1,6},{5,2,3},{5,2,4},{5,2,6},{5,3,4},
> > {5,3,6},{5,4,6},
> > {6,1,2},{6,1,3},{6,1,4},{6,1,5},{6,2,3},{6,2,4},{6,2,5},{6,3,4},
> > {6,3,5},{6,4,5}}

>
> > pts will be in the range of 4-20 or so. Speed of this operation is not
> > really critical.

>
> > The first entry in each list item ranges from 1 to pts. For any given
> > value of it, the other two entries are the subsets of Range excluding
> > the first entry. Seems simple but my solution is not.

>
> > Thank you for any tips.
>
> > Steve Gray
>
> Select[Tuples[Range[pts],3],Unequal@@#&&OrderedQ@Rest@#&]
>
> is shorter and gives the same results.

Elegant Solution!

Date Subject Author
8/19/10 Steve Gray