![]() |
|
#1
|
||||
|
||||
algorithm questionI am having a hard time trying to figure out something and was wondering if anyone could point me in the right direction,
ok....say I have x number of attributes ex. ABCD How could I write code to find every combination of the 4 letters but no two combinations have the same letters in them. A,B,C,D,AB,AC,AD,... ABC,BCD...ABCD etc. and if it has BCD then it won't have CBD. Also it has to work no matter how many attributes are entered. Any help would be greatful. Thanks so much. __________________
This message is a natural product made from recycled electrons. The slight variations in spelling and grammar enhance its individual character and beauty and in no way are to be considered flaws or defects. |
||||
|
#2
|
|||
|
|||
|
Yup this can be done, but I'm gonna struggle explaining it!
I'll take your example: ABCD. Have one loop i. For i=0, you'll tkae one letter at a time. A, B, C, D. For i=1, you'll take 2 letters at a time. One of the letters will always be A, the second will be either B, C or D. This'll give you AB, AC, AD. For i=2, you'll take 3 at a time. First 2 are AB, then either C & D. Gives you ABC, ABD. Then i=3, take 4 at a time, only ABCD. This should give you unique permutations of the letters. This algorithm will expand to any number of letters. Good? GF |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Remote Access Question | pcxgamer | Open Discussion Forum | 5 | 23-Dec-2005 00:38 |
| C++ variables question | pcxgamer | C++ Forum | 2 | 19-Sep-2003 04:01 |
| a C input question.. | tmike | C Programming Language | 2 | 19-Sep-2003 03:39 |
| a C input question | tmike | C Programming Language | 1 | 16-Sep-2003 03:31 |
| a noobish compiler question | Charunks | C++ Forum | 5 | 03-Sep-2003 03:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The