Laurent_R
Veteran
/ Moderator
Nov 6, 2013, 10:20 AM
Post #8 of 9
(5869 views)

Feel free to ask. OK, trying to explain it without currently seeing my code, I hope I don't make a mistake compared to the code. You should get the idea anyhow. Basically, @word contain thez original list of characters. I basically have to go each letter, and, for each letter thus found find all combinations of the other letters (4 in my example). @new_word contains the 4 remaining letters. I pair the first letter picked up with each of the remaining letters. I then proceed recursively the same approach, so that I will associate each pair found at the previous recursion level with each of the remaining letters (3 in the example) and so one. @current_word contains the permutation being built, so that it will have one letter at the first recursion level, 2 at the second level, etc. On the other hand, @new_word has its number of letters decreasing as we go to the next recursion level. When @new_word is empty, I have used all the available letters and can print the permutation and stop the recursive descent, go up one level to descend the next available candidate. Please be careful, do not use this recursive procedure with too many letters, it might take ages to complete (or blow up your memory). Also note that if there are some duplicate letters in your input word, you will have a number of duplicates in the output. This can be solved, but nothing is done about it so far. I hope this helps, but, again, feel free to ask if you need further advice.
