artful at rogers.com
artful at rogers.com
Fri Mar 2 15:40:02 CST 2007
For some reason, I cannot deduce what I'm doing when I work out this algorithm. I can work it out by hand, as the following table illustrates, but I am having big problems generalizing what I'm doing to account for a string of inderminate length. Assume a string of inderminate length. I want to produce all variations of said string. What is so far obvious is that the number of variations is equal to the factorial of the string. I can generate them by hand but I cannot seem to be able to deduce the algorithm that I'm using. The following table uses a 5-character string and presents only the variations that leave the first character alone (for brevity). Obviously to generate the remaining solutions I just rotate the string and repeat. The first column in the table shows the string's variants. The second column does the same, but uses numbers indicating the the sequence of the characters with relation to the original string. Here is the table: ABCDE12345 ABCED12354 ABDCE12435 ABDEC12453 ABECD12534 ABEDC12543 ACBDE13245 ACBED13254 ACDBE13425 ACDEB13452 ACEBD13524 ACEDB13542 ADBCE14235 ADBEC14253 ADCBE14325 ADCEB14352 ADEBC14523 ADECB14532 AEBCD15234 AEBDC15243 AECBD15324 AECDB15342 AEDBC15423 AEDCB15432 Please help me realize what I'm doing here. I have a function that works called Transpose(s as String, i as Integer, j as Integer), which (gasp) will transpose the letters in the string that are located at positions i and j. What I need is the algorithm that I'm using to walk through the string and generate the variations. Any insights much appreciated. Arthur