From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Help on array of pointers Date: Sat, 02 May 1998 01:17:11 -0400 Organization: Two pounds of chaos and a pinch of salt. Lines: 48 Message-ID: <354AAC57.1948@cs.com> References: <3549c0bb DOT 1910797 AT news DOT unisys DOT com DOT br> NNTP-Posting-Host: ppp110.cs.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Bruno Barberi Gnecco wrote: > > I'm writing a program that creates combinations. It (should) work this way: > there's a string containing possible characters, and I need all the possible > combinations of X characters. What I need is an array of X pointers, so I could do > this way: Be careful with your terminology. What you are describing appears to describe a permutation, not a combination. When dealing with these types of mathematical concepts, there are two formulas that can be used. Permutation (nPr) finds the number of possible arrangments of n items in groups of r. Combination (nCr) finds all possible _unique_ arrangements of n items in groups of r; i.e., the number of permutations that do not use the same items as any other. The formula for permutation can be described as follows: n! nPr = ------ (n-r)! The formula for combination can be described as follows: nPr nCr = ----- rPr This part is relatively simple, and storing all possible permutations follows naturally: create an array of nPr elements and recursively fill it. However, this can take a ridiculous amount of memory for large permutations, so I assume you're trying to just display them. As for the code to do that, I'm tired and I don't have the time to work it out. However, it should be a fairly easy operation if you take advantage of recursion. If you explain in a bit more detail exactly what you are trying to produce, then I can help further. Before you do, though, I suggest asking on a more suitable newsgroup. While I like these kinds of mental challenges, your post has absolutely nothing to do with DJGPP and there are better places to ask. Please keep this in mind, and feel free to follow up with me via email. -- --------------------------------------------------------------------- | John M. Aldrich | "It may be better to be a live jackal| | aka Fighteer I | than a dead lion, but it is better | | mailto:fighteer AT cs DOT com | still to be a live lion." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------