Possible Duplicate:
Algorithm to return all combinations of k elements from n
Generate Distinct Combinations PHP
I have an array containing a number of characters/letter,s e.g:
$seed = array('a','b','c','d','e','f',.....,'z','1','2','3',...'9');
I want to get all possible unique 4 character combinations/permutations from the seed, for example:
abcd, azxy, ag12, aaaa, etc
What’s the best way to accomplish this?
I have thought about dividing the seed array into 4 letter groups, then go through each group and generate all possible combinations of that group, but that will leave out many combinations (i.e it will process abcd and wxyz, but not abyz and wxcd)
For each character in the array, write that character followed by each of the unique 3 character strings either from the characters after it (if you actually mean combinations) or from all the characters (which is what I think you mean).
See this very similar question.
You may also want to read about recursion.
Python code
(Note: in real Python code you should use
itertools.productrather than writing it yourself.)