Permutations with repetitions
Brought to you by:
bofh28
Hi!
I have tried a bit, but I was not able to find a way to generate permutations with repetitions.That is, if I run
$ crunch 4 4 -p 0011
it displays also duplicates: it generates all the 4! = 24 permutations of 4 characters. In this case instead the permutations are 4C2 = 6.
I'm looking forward to hearing from you.
Best regards
I am not sure what you are looking for. Do you want duplicates or not?
./crunch 4 4 10
Crunch will now generate the following amount of data: 80 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 16
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001
0000
./crunch 4 4 -o test -p 1100
Crunch will now generate approximately the following amount of data: 120
bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 24
crunch: 100% completed generating output
sort test | uniq
0011
0101
0110
1001
1010
1100
If you want something else please let me know.
Thanks,
On Wed, Mar 12, 2014 at 2:16 PM, Tyrion myrddin89@users.sf.net wrote:
Related
Support Requests:
#10Thank you very much for your support.
What I was looking for is your second example, where are allowed duplicated characters and the generated strings are permutations of the first.
I was not aware of the uniq utility.
But I wondered why crunch can not generate on its own unique permutations.
The permute function is basic. It doesn't support the min max parameters.
When you have duplicate characters as the input string, 0011 in your case,
crunch treats them as unique characters that you want permuted. I haven't
found an algorithm to replace permute yet.
Thanks,
On Thu, Mar 20, 2014 at 3:47 AM, Tyrion myrddin89@users.sf.net wrote:
Related
Support Requests:
#10In this case I would suggest std::next_permutation, which does exactly that. I have tried the code myself and it is very straightforward:
std::string str = "000111";
do
{
std::cout << str << std::endl;
}
while (std::next_permutation(str.begin(), str.end()));
This function increments the initial string with the smallest possible amount using lexicographical ordering.
Clearly the loop ends when the permuted string is the biggest lexicographically.
Obviously one can also consider a std::vector<std::string> if there is more than one string to permute and apply the same function.</std::string>
Best regards