Velocity Reviews > C++ > Permutations of a set

# Permutations of a set

John Trunek
Guest
Posts: n/a

 04-05-2004
I have a set of X items, but want permutations of length Y (X > Y). I
am aware of the permutation functions in <algorithm>, but I don't
believe this will do what I want. Is there a way, either through the
STL or some other library to do this, or do I need to write my own
code?

Buster
Guest
Posts: n/a

 04-05-2004
John Trunek wrote:
> I have a set of X items, but want permutations of length Y (X > Y). I
> am aware of the permutation functions in <algorithm>, but I don't
> believe this will do what I want. Is there a way, either through the
> STL or some other library to do this, or do I need to write my own
> code?

standard). A permutation of a set S is a bijective map from S to S.
My guess is that you want the set of images of permutations of Y-
subsets of S (where S is your set of X items, and where a 'Y-subset'
of S is a subset of S which has Y elements).

You need to write your own function for this. It will be easiest
to make the function recursive, at least to begin with, I think.
Post your attempt here and I'm sure you will get help.

--
Regards,
Buster.

Buster
Guest
Posts: n/a

 04-05-2004
Buster wrote:

> John Trunek wrote:
>
>> I have a set of X items, but want permutations of length Y (X > Y). I
>> am aware of the permutation functions in <algorithm>, but I don't
>> believe this will do what I want. Is there a way, either through the
>> STL or some other library to do this, or do I need to write my own
>> code?

>
> Your terminology is non-standard (and I'm not talking about the C++
> standard). A permutation of a set S is a bijective map from S to S.
> My guess is that you want the set of images of permutations of Y-
> subsets of S (where S is your set of X items, and where a 'Y-subset'
> of S is a subset of S which has Y elements).

s/images of permutations/permutations of images/

> You need to write your own function for this. It will be easiest
> to make the function recursive, at least to begin with, I think.
> Post your attempt here and I'm sure you will get help.
>

--
Regards,
Buster.

Buster
Guest
Posts: n/a

 04-05-2004

Buster wrote:

> Buster wrote:
>
>> John Trunek wrote:
>>
>>> I have a set of X items, but want permutations of length Y (X > Y). I
>>> am aware of the permutation functions in <algorithm>, but I don't
>>> believe this will do what I want. Is there a way, either through the
>>> STL or some other library to do this, or do I need to write my own
>>> code?

>>
>>
>> Your terminology is non-standard (and I'm not talking about the C++
>> standard). A permutation of a set S is a bijective map from S to S.
>> My guess is that you want the set of images of permutations of Y-
>> subsets of S (where S is your set of X items, and where a 'Y-subset'
>> of S is a subset of S which has Y elements).

>
> s/images of permutations/permutations of images/

No, sorry, let it stand. I meant the images of the permutations,
viewing the permutations as functions, as I said. To be clear, these
sets, the images of the permutations of a set T (say), are what might
be called the 'results of permuting T', or just 'the permutations of T',
speaking less formally.

Another obscurity is the meaning of the word 'set' in this context.
The OP may have been referring to the standard library's 'set' class
template, as well as alluding to the set-theoretic term 'set'.

>> You need to write your own function for this. It will be easiest
>> to make the function recursive, at least to begin with, I think.
>> Post your attempt here and I'm sure you will get help.
>>

>

--
Regards,
Buster.

Alf P. Steinbach
Guest
Posts: n/a

 04-05-2004
* Buster <(E-Mail Removed)> schriebt:
> John Trunek wrote:
> > I have a set of X items, but want permutations of length Y (X > Y). I
> > am aware of the permutation functions in <algorithm>, but I don't
> > believe this will do what I want. Is there a way, either through the
> > STL or some other library to do this, or do I need to write my own
> > code?

>
> Your terminology is non-standard (and I'm not talking about the C++
> standard). A permutation of a set S is a bijective map from S to S.
> My guess is that you want the set of images of permutations of Y-
> subsets of S (where S is your set of X items, and where a 'Y-subset'
> of S is a subset of S which has Y elements).

I think it's more reasonable to assume that the OP wants to generate all
possible passwords of length Y from some character set with X characters.
In which case it's combinations, not permutations. I think.

> You need to write your own function for this. It will be easiest
> to make the function recursive, at least to begin with, I think.
> Post your attempt here and I'm sure you will get help.

If assumption above is correct then the easiest is probably to just
count up; but the easiest programmatically will not be very efficient
in light of some combinations being far more probable than others.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Buster
Guest
Posts: n/a

 04-06-2004
Alf P. Steinbach wrote:

> * Buster <(E-Mail Removed)> schriebt:
>
>>John Trunek wrote:
>>
>>>I have a set of X items, but want permutations of length Y (X > Y). I
>>>am aware of the permutation functions in <algorithm>, but I don't
>>>believe this will do what I want. Is there a way, either through the
>>>STL or some other library to do this, or do I need to write my own
>>>code?

>>
>>standard). A permutation of a set S is a bijective map from S to S.
>>My guess is that you want the set of images of permutations of Y-
>>subsets of S (where S is your set of X items, and where a 'Y-subset'
>>of S is a subset of S which has Y elements).

>
> I think it's more reasonable to assume that the OP wants to generate all
> possible passwords of length Y from some character set with X characters.
> In which case it's combinations, not permutations. I think.

The original post doesn't suggest that to me. Looks like we'll need a

>>You need to write your own function for this. It will be easiest
>>to make the function recursive, at least to begin with, I think.
>>Post your attempt here and I'm sure you will get help.

>
> If assumption above is correct then the easiest is probably to just
> count up; but the easiest programmatically will not be very efficient
> in light of some combinations being far more probable than others.

All passwords of length Y from a character set with X characters are
equally 'probable' (think 'lottery'). In the obvious thought experiment,
each distinct password has probability 'std:ow (X, -Y);'.

--
Regards,
Buster.

Steven T. Hatton
Guest
Posts: n/a

 04-06-2004
John Trunek wrote:

> I have a set of X items, but want permutations of length Y (X > Y). I
> am aware of the permutation functions in <algorithm>, but I don't
> believe this will do what I want. Is there a way, either through the
> STL or some other library to do this, or do I need to write my own
> code?

If permutations is what you really want, it's actually quite easy. In a
word, /recursion/.
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org

Alf P. Steinbach
Guest
Posts: n/a

 04-06-2004
* Buster <(E-Mail Removed)> schriebt:
>
> All passwords of length Y from a character set with X characters are
> equally 'probable' (think 'lottery'). In the obvious thought experiment,
> each distinct password has probability 'std:ow (X, -Y);'.

That turns out not to be the case. Some passwords are used far more often
than others. In particular, passwords that contain English words are used
extremely more often than those that do not.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Alf P. Steinbach
Guest
Posts: n/a

 04-06-2004
* "Steven T. Hatton" <(E-Mail Removed)> schriebt:
> John Trunek wrote:
>
> > I have a set of X items, but want permutations of length Y (X > Y). I
> > am aware of the permutation functions in <algorithm>, but I don't
> > believe this will do what I want. Is there a way, either through the
> > STL or some other library to do this, or do I need to write my own
> > code?

>
> If permutations is what you really want, it's actually quite easy. In a
> word, /recursion/.

You can also enumerate permutations using the factorial number system
plus a bitset.

I once had a letter to the editor about that printed in Computer Language,
the now defunct magazine infamous for its shameless promotion of Jolt Cola.

fundamental ways of generating permutations) "The third way is the charm".

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

bartek
Guest
Posts: n/a

 04-06-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Alf P. Steinbach) wrote in
news:(E-Mail Removed):

> * Buster <(E-Mail Removed)> schriebt:
>>
>> All passwords of length Y from a character set with X characters are
>> equally 'probable' (think 'lottery'). In the obvious thought
>> experiment, each distinct password has probability 'std:ow (X,
>> -Y);'.

>
> That turns out not to be the case. Some passwords are used far more
> often than others. In particular, passwords that contain English
> words are used extremely more often than those that do not.

Not necessarily... 'qwerty' 'asdfg' and '1234' are not English words AFAIK.