A case with Combinations in Sets

Discussion in 'Perl Misc' started by anirbid.banerjee@gmail.com, Feb 19, 2008.

  1. Guest

    Hi,

    I have two Sets A and B with N DISTINCT elements each. Both A and B
    are related to each other so that B contains complement of A. For eg.A
    = {a, b, c} , B = {a*, b* c*}. I would need a perl script to generate
    all possible combinations between A and B satisfying the following
    conditions:

    a) The number of elements in the Combined set n(C) = N.
    b) None of the combination should contain both an element and its
    complement : i.e. {a, a*, b}, {b,c, c*} are invalid combinations.
    c) There should be exactly 2^N combinations.

    Regards,
    Anirbid
    , Feb 19, 2008
    #1
    1. Advertising

  2. Guest

    "" <> wrote:
    > Hi,
    >
    > I have two Sets A and B with N DISTINCT elements each. Both A and B
    > are related to each other so that B contains complement of A. For eg.A
    > = {a, b, c} , B = {a*, b* c*}. I would need a perl script to generate
    > all possible combinations between A and B satisfying the following
    > conditions:


    Since set B is completely and readily determined by set A, there is really
    no point in actually having it. Just let it be implied by A.

    > a) The number of elements in the Combined set n(C) = N.
    > b) None of the combination should contain both an element and its
    > complement : i.e. {a, a*, b}, {b,c, c*} are invalid combinations.
    > c) There should be exactly 2^N combinations.


    So take all numbers from 0 to 2^N and map each bit-position to one of the
    elements in A. Call the ones the elements and the zeros the complements to
    the elements.

    $n=6;
    foreach (0..2**$n-1) {
    print sprintf "%0${n}b", $_ ;
    };


    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , Feb 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks
    Replies:
    2
    Views:
    1,247
    Steve Franks
    Jun 10, 2004
  2. Tee
    Replies:
    3
    Views:
    7,793
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  3. Matt
    Replies:
    8
    Views:
    396
  4. johkar
    Replies:
    6
    Views:
    922
    johkar
    Apr 19, 2009
  5. Srinivas Jonnalagadda

    Generating combinations from multiple sets

    Srinivas Jonnalagadda, Jan 16, 2006, in forum: Ruby
    Replies:
    1
    Views:
    139
    Srinivas Jonnalagadda
    Jan 16, 2006
Loading...

Share This Page