import itertools
list(itertools.permutations('abc'))Generating all permutations, combinations, and power set of a string (2012)
11–20 of 48 posts
Re: Generating all permutations, combinations, and power set of a string (2012)
#12 class Permutations
{
public:
Permutations(int val_n) : n(val_n), _more(true)
{
a = new int[n];
for (int i = 0; i = 0; i--)
if (a[i] i; j--)
if (a[j] > a[i])
{
swap(a[j], a[i]);
break;
}
i++;
for (int j = n-1; j > i; j--, i++)
swap(a[j], a[i]);
break;
}
}
int operator[](int i) { return a[i]; }
int n;
private:
void swap(int &x, int &y)
{
int h = x;
x = y;
y = h;
}
bool _more;
int *a;
};Re: Generating all permutations, combinations, and power set of a string (2012)
#13Re: Generating all permutations, combinations, and power set of a string (2012)
#14Re: Generating all permutations, combinations, and power set of a string (2012)
#15Posts like this are why I love HN. I recently wrote a program to find anagrams of a given string (a Countdown solver if you live in the UK). It includes a really naive method for generating all possible permutations of the string, but reading this post I can immediately see a far better way to do it. That's my weekend taken care of! thanks to the poster and author.
There was a recent post about anagrams and the author just put all the letters in alphabetical order and then compared the words, which was more efficient than generating permutations.
Re: Generating all permutations, combinations, and power set of a string (2012)
#16Earlier quoted context omitted.
There was a recent post about anagrams and the author just put all the letters in alphabetical order and then compared the words, which was more efficient than generating permutations.
Sounds interesting, do you have a link?
Re: Generating all permutations, combinations, and power set of a string (2012)
#17If anyone wants to know how deep down the rabbit hole this stuff goes, they should read this blog post [1] on writing a Levenshtein Automaton to speed up fuzzy matching in Lucene by 100 times. It gets deep! [1]: http://blog.mikemccandless.com/2011/03/lucenes-fuzzyquery-is...
[1]: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.6...
Re: Generating all permutations, combinations, and power set of a string (2012)
#18Posts like this are why I love HN. I recently wrote a program to find anagrams of a given string (a Countdown solver if you live in the UK). It includes a really naive method for generating all possible permutations of the string, but reading this post I can immediately see a far better way to do it. That's my weekend taken care of! thanks to the poster and author.
There was a recent post about anagrams and the author just put all the letters in alphabetical order and then compared the words, which was more efficient than generating permutations.
https://github.com/Rhebel/DailyProgrammer/blob/master/DailyP...
I know my code is super verbose compared to other people's but I'd rather be understood than clever.
Re: Generating all permutations, combinations, and power set of a string (2012)
#19Re: Generating all permutations, combinations, and power set of a string (2012)
#20Posts like this are why I love HN. I recently wrote a program to find anagrams of a given string (a Countdown solver if you live in the UK). It includes a really naive method for generating all possible permutations of the string, but reading this post I can immediately see a far better way to do it. That's my weekend taken care of! thanks to the poster and author.