Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2004, 06:15 PM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default i need to make this program

i need to make the program to take a number between 2,9

and the program make possible combinations in form of sets where {1,2} the same as {2,1}
i don't need the program to display both sets.

also when you give the program a number between 2,9
for example :
for 2
{1,2}
for 3
{1,2,3}
for 4
{1,2,3,4}

and continue displaying all possible combination in a form of sets which contains a number of elements specified by the user of the program.

if you don't understand me please post a reply.






 
Old October 24th, 2004, 05:51 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Do you need to make Subsets?
if so,i.e for 2
your program should generate these,
{},{1},{2},{1,2}
Did I guess your meaning correctly?

--------------------------------------------
Mehdi.:)
 
Old October 24th, 2004, 09:27 AM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

look
if i have a set of {1,2,3,4,5,6,7,8,9,10}

for a combination of 2 the program will produce
{1,2} {1,3} {1,4} ... etc..
for a combination of 3 will produce
{1,2,3} {1,2,4} and so on.

with a condition that {1,2} equals {2,1} so no need to generate both, just one is enough

 
Old October 24th, 2004, 01:25 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

okay I got what you wanted,
I can tell you a way then you can write your program in your favorite syntax
suppose our set is {1,2,3},
then for generating Subsets we generate numbers between 0 to 2^3-1(in binary mode) then from these numbers we can determine which subset should be printed(under your circumstance,you should print some of them not all of them)
take a look at the numbers and their equivalent subsets,

000 <--->{}
001 <--->{3}
010 <--->{2}
011 <--->{2,3}
100 <--->{1}
101 <--->{1,3}
110 <--->{1,2}
111 <--->{1,2,3}

this I told gave you all possible combinations then for example for combination of 2 you should select numbers that have two 1 in their digits(I mean these numbers :011,101,110)
I think you can easily implement this logic and write your program.

--------------------------------------------
Mehdi.:)
 
Old October 24th, 2004, 06:14 PM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your reply

that is a good idea , but i think it doesn't match my problem.
my elements are stored in an array for example
A={a,b,c,d,e,f,g,h}
and i need to make possible combination between 2,3,..,5 elements without repeating

is your idea match that in your opinion
 
Old October 25th, 2004, 06:21 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think yes,
I think you didnt get my meaning completely,
suppose our set is {a,b,c} ...
now consider 101,the first digit is 1 so you print a,the second digit is 0 so you dont print b,and the third digit is 1,so you print c,and rest of them like above,

000 <--->{}
001 <--->{c}
010 <--->{b}
011 <--->{b,c}
100 <--->{a}
101 <--->{a,c}
110 <--->{a,b}
111 <--->{a,b,c}

then,
for combination of 0 you should select these numbers,
000(there is no 1 in these numbers)
for combination of 1 you should select these numbers,
001,010,100 (there is one 1 in these numbers)
for combination of 2 you should select these numbers,
011,101,110 (there are two 1's in these numbers)
for combination of 3 you should select these numbers,
111 (there are three 1's in these numbers)
in my opinion that solves your problem very well.

--------------------------------------------
Mehdi.:)
 
Old October 25th, 2004, 06:43 AM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if i ask you to write the code of that algorithm, is that will annoy you.

 
Old October 25th, 2004, 12:25 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

dont expect me to write your code,
anyway,
do these steps
suppose our set is {a,b,c}
1-make an Arraylist(the capacity is 2^3=8)
2-initialize that arraylist(set its every element to zero)
3-make a new method for increasing your arraylist one unit
4-make another method for getting the numbers of 1's in the ArrayList
5-put the increaser method in a loop cycle and check the elements of your array for matching the combinations
(I think I've explained them enough for you to write your code)
anyway,keep in touch in any faced problem.

--------------------------------------------
Mehdi.:)
 
Old October 25th, 2004, 02:17 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
////////////////////////////////////////////////////////////

        private void initialize(ref ArrayList a)
        {
            for(int i=0;i<a.Capacity;i++)
            {
                a.Add(0);
                //textBox1.Text+=a[i].ToString()+",";
            }
        }
        private void AddOneUnit(ref ArrayList a)
        {
            int i;
            for(i=a.Capacity-1;((Convert.ToInt32(a[i])==1)&&(i>0));i--)
                a[i]=0;
            a[i]=1;
        }
        private string print(ref ArrayList a)
        {
            string s="{";

            for(int i=0;i<a.Capacity;i++)
            {
                //if(System.Convert.ToInt32(a[i])==1)
                s+=a[i].ToString()+",";
            }
            s=s.Remove(s.Length-1,1);
            s+="}";
            return s;
        }
        private int GetTheNumbersOf1(ref ArrayList a)
        {
            int c=0;
            for(int i=0;i<a.Capacity;i++)
                if(System.Convert.ToInt32(a[i])==1) c++;
            return c;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            const int m=3;//m is the lenght of your set
            const int n=8;//2^3
            const int combination=2;//get it from user
            string output="";
            ArrayList a=new ArrayList(m);
            this.initialize(ref a);
            for(int i=0;i<n;i++)
            {
                if(this.GetTheNumbersOf1(ref a)==combination)
                    output+=this.print(ref a)+"-";
                this.AddOneUnit(ref a);
            }
            output=output.Remove(output.Length-1,1);
            textBox1.Text=output;
        }
/*//////////////////////////////////////////////////////////
Copyright (c) 2004, Mehdi
Feel free to use and distribute in compiled form.
//////////////////////////////////////////////////////////*/
--------------------------------------------
Mehdi.:)
 
Old October 25th, 2004, 05:28 PM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you "mehdi"






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make me a Program?? benhar03 VB Databases Basics 3 February 11th, 2008 10:34 PM
I need help to make this enabled thing program... psycoblaster Visual Basic 2005 Basics 0 November 27th, 2007 07:36 AM
How to make program chat using C++ bLo C++ Programming 8 March 20th, 2007 01:35 AM
How to make a program full screen snowy0 VB How-To 1 August 6th, 2004 07:41 PM
how to make a program which plays tunes cbpanchal VB How-To 0 September 21st, 2003 09:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.