# Create all possible words using a set or letters

Given a list of letters,

letters = { "A", "B", ..., "F" }


is it possible to get Mathematica to generate all ‘words’ (in this example, 6 letter words), if only one letter can be used one time only, e.g. ABCDEF, ABCDFE, …? TIA.

Pemutations will do it:

letters = {"a", "b", "c"};
Permutations[letters, {3}]
{{"a", "b", "c"}, {"a", "c", "b"}, {"b", "a", "c"},
{"b", "c", "a"}, {"c", "a", "b"}, {"c", "b", "a"}}


To get all six-letter words:

letters = {"a", "b", "c", "d", "e", "f"};
perms = Permutations[letters, {6}];
StringJoin /@ perms

{"abcdef", "abcdfe", "abcedf", "abcefd", "abcfde" ... etc.


there are a lot of them.

You can create permutations with all of the letters as strings with:

StringJoin /@ Permutations[letters]


If you want lists of the individual letters just use:

Permutations[letters]


Check the documentation of Permutations to learn about permutations with subsets of letters. If you want to use each letter more than once, look at the documentation for Tuples.

• Thanks(x2). Is there some way to check how many words contain a ‘sub-word’, like ‘ab’ or even a set of ‘sub-words’ like ‘ab’ and ‘cd’? And is there any web page or text book that deals with combinatorics in Mathematica (on a more ‘basic’ level) that I could visit/buy and read? – mf67 Mar 24 at 2:54

If I follow the OP's question, I think they want the following:

letters = {"a", "b", "c"};
p = Permutations[letters, {#}] & /@ Range[Length[letters]];
(StringJoin[#] & /@ #) & /@ p

{{a, b, c}, {ab, ac, ba, bc, ca, cb}, {abc, acb, bac, bca, cab, cba}}

• No, the OP requested all six letter words. – m_goldberg Mar 24 at 11:22
• Your last line can be written more cleanly as Map@StringJoin/@p or Map[StringJoin, p, {2}]. – Doorknob Mar 24 at 22:48