Re: Simple program needed (help)
- Posted by Ricardo M. Forno <rmforno at tutopia.com> Mar 07, 2006
- 397 views
faz wrote: > > Hi > > I hope someone can help me out with a very SIMPLE program > about whole string permutations. That is: given a list of strings, > the required outcome is a complete set of all their possible permutations. > It's like character permutations of a string, but this time it is > whole strings instead of single characters that have to be permuted. > > I need this because I don't remember exactly the password to open > my zipped archives, but i do remember the bits of strings > that made up the long passphrase. > > Could someone kindly write a simple program that, after reading a set of > strings contained in a .txt file (one string on each line), > produces as output another .txt file containing all the possible > permutations/combinations of those strings. > > For example, the text file with the set of strings may contain: > > HOUSE > jolly > --- > 0& > 99 > > > and the output file contains: > > HOUSE > HOUSEjolly > HOUSE--- > HOUSE0& > > and so on... > ...with the word combinations growing extensively, > so as to exhaust all the possibilities: > > e.g. > > ---99jolly0& > jolly0&---99HOUSE > > etc. etc. > > Unfortunately I am not able to program it myself, so > I would appreciate if someone could write this piece of > software, compile it (for DOS or Windows) and send it to: > > lory88 at gmail . com > > > I thank you all in advance. > > Lory Hi, Lory. At this time I cannot completely answer your request, but I think the following code, that you can also find in my General Funtons package, will help you to get your job done. --/topic STATISTICS / PROBABILITIES ROUTINES --/func Permutation(sequence set, integer size, integer which) --/desc Obtains a permutation of the elements of a set --/ret A sequence containing a specified permutation of the argument sequence --Returns a sequence containing the permutation with size 'size', -- numbered 'which', from the set 'set'. --The set is any sequence of objects, and so is the result. --'which' starts at 1 and goes to the number of existing permutations -- of this size. --If 'which' is out of bounds, an atom containing -1 is returned. --Thanks to Henri Goffin for a correction. --Example: Permutation("ABCDE", 3, 4) gives "ACB" global function Permutation(sequence set, integer size, integer which) integer c, len, a len = length(set) if size <= 0 then return - 1 elsif size = 1 then if which <= len then return {set[which]} else return - 1 end if end if c = 1 for i = len - size + 1 to len - 1 do c *= i end for a = floor((which - 1) / c) which -= a * c a += 1 if a > len or a <= 0 then return - 1 end if return {set[a]} & Permutation(set[1..a-1] & set[a+1..len], size - 1, which) end function You should call it with increasing values for 'which', starting at 1. Regards