Combination&&arrange in order 
Author Message
 Combination&&arrange in order

Dear All:
         there is a program to show balls arrange in order
,for example 5 balls should have 120 cases ,but different colors ball should
combination,like 2 red color balls and 3 white color balls,total 5 balls
have 10 cases
like:{11000,10100,10010,10001.01100,01010,01001,00110,00011,00101}
now I just can show 120 cases in different 5 colors ball,can't exclude same
case in cases Y_Y
Is there any guys can give me a hand?Thanks!
/***************************************************************************
**********/
#include<stdio.h>
#include<conio.h>
#define size 5

int counter=1,level=0;
int a[size];
char ch[size],out[size];

pp(num)
{
   int i;

   level+=1;
   for(i=0;i<num;i++)
      if(a[i]==0)
      {
         a[i]=1;
         out[level-1]=ch[i];
         if(level==num)
     printf("\n%3d %s",counter++,out);}
         pp(num);
         a[i]=0;
      }
   level--;

Quote:
}

main()
{  
   int num=0;

   printf("please input \n");
   printf("for example:5 balls 2 collors input 00011\n");
   printf("now input:");
   printf("\n user input was :");
   while((ch[num]=getche())!='\r')
   {
      a[num]=0;
      num+=1;
   }
   ch[num]='\0';        
   pp(num);
   printf("\n\n%3d balls%4d kinds of condition ^.^",num,counter-1);

Quote:
}



Thu, 22 Aug 2002 03:00:00 GMT  
 Combination&&arrange in order

Quote:

> there is a program to show balls arrange in order, for example

  5 balls should have 120 cases, but different colors ball should
  combination,like 2 red color balls and 3 white color balls,
  total 5 balls have 10 cases like: {11000, 10100, 10010, 10001,
  01100, 01010, 01001, 00110, 00011, 00101} now I just can show
  120 cases in different 5 colors ball,can't exclude same case in
  cases Y_Y Is there any guys can give me a hand?Thanks!
               [   Code deleted   ]
-----------------------------------------------------------------
Since the code you posted doesn't work, this "help" is based on
what I THINK you're trying to do.  It looks like you're trying to
use a FOR loop to select the object in the "i"th position by
stepping through the set, then making a recursive call to select
the object in the "i+1"th position.  If your set consists of
groups of non-unique objects and you want to eliminate
permutations which only involve the "swapping" of positions
between objects of the same type, you simply have to make the
recursive call conditional upon the object just chosen being
either the first object selected for that position or the first
object of its type to be selected for that position.

Because you are using a FOR loop, the first condition is easily
determined; if it is the 1st iteration of the loop, the object is
the first of any type chosen for that position.  The second
condition is also easy to determine IF one makes the assumption
that the objects of similar type are grouped together in the
array, that is that all objects of the same type are located in a
contiguous block.  If this condition is true, then one can simply
check the type of object used in that position just prior to the
selection of the current element in order to determine if the
current selection is the first of its type to be chosen for that
position in the permutation.
-----------------------------------------------------------------
Derek Asari

Sent via Deja.com http://www.deja.com/
Before you buy.



Thu, 22 Aug 2002 03:00:00 GMT  
 Combination&&arrange in order

Quote:

>Dear All:
>         there is a program to show balls arrange in order
>,for example 5 balls should have 120 cases ,but different colors ball
should
>combination,like 2 red color balls and 3 white color balls,total 5
balls
>have 10 cases
>like:{11000,10100,10010,10001.01100,01010,01001,00110,00011,00101}
>now I just can show 120 cases in different 5 colors ball,can't exclude
same
>case in cases Y_Y
>Is there any guys can give me a hand?Thanks!

I bet you'd get a really cool answer in comp.lang.lisp. That assignment
would be much better if it was from a LISP class (intro to AI, etc).
Actually, Miranda solutions would be cool too.

Wes



Sun, 25 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ***&&&>>> HELP --- CXL --- HELP <<<&&&****

2. owner drawn dynamic LB - arrange order?

3. Linker error 2001 @&(#&@#&$@

4. Linker error 2001 @&(#&@#&$@

5. testing & adjusting byte ordering

6. Bit operation & order Q Thanks

7. Bit operation & order Q

8. Up&Down sort order triangle in ListCtrl

9. sorted object on more then one field by any field combination & asc desc order

10. Question on In-order, pre-order & post-order

11. CCmdTarget && delete && CList

12. /clr & edit &continue

 

 
Powered by phpBB® Forum Software