Permutations of a set

Discussion in 'C++' started by John Trunek, Apr 5, 2004.

  1. John Trunek

    John Trunek Guest

    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?
     
    John Trunek, Apr 5, 2004
    #1
    1. Advertising

  2. John Trunek

    Buster Guest

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

    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, Apr 6, 2004
    #2
    1. Advertising

  3. John Trunek

    Buster Guest

    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, Apr 6, 2004
    #3
  4. John Trunek

    Buster Guest

    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.
     
    Buster, Apr 6, 2004
    #4
  5. * Buster <> 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?
     
    Alf P. Steinbach, Apr 6, 2004
    #5
  6. John Trunek

    Buster Guest

    Alf P. Steinbach wrote:

    > * Buster <> 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.


    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"?)

    >>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::pow (X, -Y);'.

    --
    Regards,
    Buster.
     
    Buster, Apr 6, 2004
    #6
  7. 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
     
    Steven T. Hatton, Apr 6, 2004
    #7
  8. * Buster <> 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::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: 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, Apr 6, 2004
    #8
  9. * "Steven T. Hatton" <> 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.

    The editors added the heading (after earlier discussions of Knuth's two
    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?
     
    Alf P. Steinbach, Apr 6, 2004
    #9
  10. John Trunek

    bartek Guest

    (Alf P. Steinbach) wrote in
    news::

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


    Not necessarily... 'qwerty' 'asdfg' and '1234' are not English words AFAIK.
    :)
     
    bartek, Apr 6, 2004
    #10
  11. John Trunek

    Rolf Magnus Guest

    bartek wrote:

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


    Some (hopefully many) systems will at least warn you that your password
    is too trivial, so your examples might not be seen that often.
     
    Rolf Magnus, Apr 6, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karsten Wutzke

    Permutations of instances in array

    Karsten Wutzke, Mar 2, 2004, in forum: Java
    Replies:
    5
    Views:
    17,824
    Chris Lamprecht
    Mar 4, 2004
  2. Hendrik Maryns
    Replies:
    0
    Views:
    352
    Hendrik Maryns
    Mar 3, 2006
  3. Roger
    Replies:
    1
    Views:
    437
    Martin Magnusson
    Sep 24, 2003
  4. Ed Neukirch

    Permutations

    Ed Neukirch, Dec 24, 2003, in forum: C++
    Replies:
    7
    Views:
    650
    Mike Hewson
    Dec 27, 2003
  5. OL/2
    Replies:
    2
    Views:
    144
Loading...

Share This Page