Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

RE: subsets of a set

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70041] RE: [mg70001] subsets of a set
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 1 Oct 2006 04:08:42 -0400 (EDT)

Dimitris,

I think you may want...

Needs["DiscreteMath`Combinatorica`"]

KSubsets[Range[7], 3]
{{1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 2, 6}, {1, 2, 7}, {1, 3, 4}, {1, 3,
    5}, {1, 3, 6}, {1, 3, 7}, {1, 4, 5}, {1, 4, 6}, {1, 4, 7}, {1, 5, 6},
{1,
    5, 7}, {1, 6, 7}, {2, 3, 4}, {2, 3, 5}, {2, 3, 6}, {2, 3, 7}, {2, 4,
    5}, {2, 4, 6}, {2, 4, 7}, {2, 5, 6}, {2, 5, 7}, {2, 6, 7}, {3, 4, 5},
{3,
    4, 6}, {3, 4, 7}, {3, 5, 6}, {3, 5, 7}, {3, 6, 7}, {4, 5, 6}, {4, 5,
    7}, {4, 6, 7}, {5, 6, 7}}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/





From: dimmechan at yahoo.com [mailto:dimmechan at yahoo.com]
To: mathgroup at smc.vnet.net


In page 226 of John Gray's Mastering Mathematica
(unfortunately I had the 1994's edition)
there is the following exercise:

"Given a finite set (presented as a list) and an integer k
find all k-element subsets of the set".

There is one solution however for practicing (no there is no professor
that asked me this for homeworks! I work individually...) I search for
other

So considering the following list

lst = Tuples[Range[7], 3];

I can erase the sublists containg at least two same elements

Cases[lst, {x_, y_, z_} /; x ß?  y && x ß?  z && y ß?  z]

but after I cannot erase the permutations of e.g. {1,2,3};
that is in the output there are the sublists {1,2,3},
{2,1,3},{3,1,2} e.t.c. for other triplets.

I look for both functional as well pattern matching approaches.

Thanks



  • Prev by Date: Re: subsets of a set
  • Next by Date: Re: four argument form of infix
  • Previous by thread: Re: subsets of a set
  • Next by thread: Re: subsets of a set