GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Oct-2003, 15:50
calculus87's Avatar
calculus87 calculus87 is offline
Junior Member
 
Join Date: Sep 2003
Location: FLorida
Posts: 41
calculus87 is on a distinguished road

algorithm question


I 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  
Old 11-Oct-2003, 10:24
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
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 GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 16:20.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.