python todas as permutações de uma corda
>>> from itertools import permutations
>>> perms = [''.join(p) for p in permutations('stack')]
>>> perms
Worrisome Wallaby
>>> from itertools import permutations
>>> perms = [''.join(p) for p in permutations('stack')]
>>> perms
void permute(string a, int l, int r)
{
// Base case
if (l == r)
cout<<a<<endl;
else
{
// Permutations made
for (int i = l; i <= r; i++)
{
// Swapping done
swap(a[l], a[i]);
// Recursion called
permute(a, l+1, r);
//backtrack
swap(a[l], a[i]);
}
}
}
# get all permutations of string
import itertools
for p in itertools.permutations('123'):
print(p) # ( ' 1 ', ' 2 ', ' 3 ') ( ' 1 ' , ' 3 ', ' 2 ' ) ( ' 2 ', ' 1 ', ' 3 ' )