Function Repository Resource:

StringPermutations

Source Notebook

Get character permutations for a string

Contributed by: Arnoud Buzing

ResourceFunction["StringPermutations"][string]

generates a list of all possible permutations of the characters in string.

ResourceFunction["StringPermutations"][string,n]

gives all permutations containing at most n characters.

ResourceFunction["StringPermutations"][string,{n}]

gives all permutations containing exactly n characters.

Details and Options

ResourceFunction["StringPermutations"] is implemented with Characters and Permutations.
ResourceFunction["StringPermutations"] is the String analog of Permutations of a List.

Examples

Basic Examples (3) 

Permutations of "cat":

In[1]:=
ResourceFunction["StringPermutations"]["cat"]
Out[1]=

Three character permutations of "horse":

In[2]:=
ResourceFunction["StringPermutations"]["horse", {3}]
Out[2]=

Zero, one, two and three character permutations of "garden":

In[3]:=
ResourceFunction["StringPermutations"]["garden", 3]
Out[3]=

Properties and Relations (1) 

StringPermutations can also be implemented with the resource function StringFunction:

In[4]:=
stringPermutations = ResourceFunction["StringFunction"][Permutations]
Out[4]=
In[5]:=
stringPermutations["cat"] === ResourceFunction["StringPermutations"]["cat"]
Out[5]=
In[6]:=
stringPermutations["horse", {3}] === ResourceFunction["StringPermutations"]["horse", {3}]
Out[6]=

Publisher

Arnoud Buzing

Version History

  • 1.0.0 – 01 June 2020

Related Resources

License Information