permuting a string (was Re: Speed)

Beat Cornaz B.Cornaz at gmx.net
Sat Aug 30 07:24:02 EDT 2014


 Sat, 30 Aug 2014  Geoff wrote :

> Used Alex's code to generate a list of the permutations of all the characters that were duplicates.
> Substituted in unique characters for each instance of the duplicates.
> Ran my permutation code on the rest of the characters, with the addition of the duplicates-permutation-strings as the base case.

I was working on the same line, but from the other end. I start with the characters that are not duplicate and use your very fast code to get all the permutations.
The I slot in, one for one, all the duplicate elements on all possible positions. After slotting in each duplicate element, I delete duplicate lines, so in the next run of inserting the next duplicate element, I will have to do less, as the duplicate lines have been deleted. I am not completely finished with the script & testing. I will post it as soon as possible.

I also tried to serialise Geoff's script and looked if I could get rid of duplicates inside of the script. I did not manage as yet. But the serialised script is a bit easier for me to play around with, as I can better watch the different variables.


This is my serialised version of Geoff's original script :

function BC4_PermMech_Geoff_Serial_Chars N
     put "01" & cr & "10"& cr  into T
   
   repeat with x = 2 to N
      
        repeat with i = 0 to x
              put T into T2
              replace i with x in T2
              replace cr with i & cr in T2
              put T2 after R
        end repeat
   
      put R into T
      put empty into R
   end repeat
   
   delete char -1 of T
   
     return  T
end BC4_PermMech_Geoff_Serial_Chars



All the best, Beat


More information about the use-livecode mailing list