Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > A case with Combinations in Sets

Reply
Thread Tools

A case with Combinations in Sets

 
 
anirbid.banerjee@gmail.com
Guest
Posts: n/a
 
      02-19-2008
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
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      02-19-2008
"(E-Mail Removed)" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting unique combinations from two node sets johkar XML 6 04-19-2009 03:55 AM
Case-insensitive collections (sets, maps, etc.) Matt Java 8 03-15-2007 01:58 PM
Generating combinations from multiple sets Srinivas Jonnalagadda Ruby 1 01-16-2006 12:19 PM
millions combinations of test vectors for ALU Lily VHDL 16 05-10-2004 07:22 PM
MCSE 2000 exam combinations TheXman MCSE 1 12-05-2003 01:27 PM



Advertisments