Permutations of a set

J

John Trunek

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?
 
B

Buster

John said:
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).

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.
 
B

Buster

Buster said:
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/
 
B

Buster

Buster said:
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'.
 
A

Alf P. Steinbach

* Buster said:
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.
 
B

Buster

Alf said:
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
clarification. (I don't quite follow your suggestion either. Is "xyz"
the same password as "zyx"?)
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::pow (X, -Y);'.
 
S

Steven T. Hatton

John said:
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/.
 
A

Alf P. Steinbach

* Buster said:
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::pow (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

Alf P. Steinbach

* "Steven T. Hatton said:
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.

The editors added the heading (after earlier discussions of Knuth's two
fundamental ways of generating permutations) "The third way is the charm".
 
B

bartek

(e-mail address removed) (Alf P. Steinbach) wrote in
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.
:)
 
R

Rolf Magnus

bartek said:
Not necessarily... 'qwerty' 'asdfg' and '1234' are not English words
AFAIK.
:)

Some (hopefully many) systems will at least warn you that your password
is too trivial, so your examples might not be seen that often.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top