Thread: New but efficient way to...

  1. #1
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532

    New but efficient way to...

    Hi, I'm just looking for new things to learn(which equals something to do), so what is an unusual or complicated, BUT EFFICIENT, way to list all the possibilities of a string. For example, I have a string, and want to list all the different combinations that the letters in the string could have, so in a sense, scramble the word and list all the different ways the word could be scrambled? Is there many different ways to do it? What way would you do it? Thanks.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    think smaller to find your answer. How many different combinations of a base 10 decimal system can 2 digits have? Even lower? think in binary. You should come across your algorithm sooner or later.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Yeah, thanks for the reply, but I'm looking for new ways/unusual ways to do this same task.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Well, I'm not sure this is what you are looking for, but see if you can get code to work using next_permutation from <algorithm>. That is how I would do it (the code is already available, tested, debugged and optimized).

    Also consider looking at the code of how your STL implements that method, to see if you can decipher it. That might be its own challenge.

    Using existing functions is probably not what you meant by unusual, but for many C++ programmers actually using the STL might be considered unusual.

  5. #5
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Yes Daved, that is exactly the kind of thing I was looking for. That is a way I have never heard of and looks interesting, thank you. Any other methods are also welcome.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Hey, since that pretty much died, how about anybody posting any way they would do it. No matter if that way is commonly used or very bizarre. It would be fun to try out and see how many different ways there are to do one thing.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Most Efficient Way to Check a Variable Is A Whole Number
    By bengreenwood in forum C++ Programming
    Replies: 29
    Last Post: 05-28-2009, 01:33 PM
  2. Is std::map efficient for this problem?
    By dudeomanodude in forum C++ Programming
    Replies: 12
    Last Post: 04-10-2008, 02:15 PM
  3. Efficient Algorithm
    By purple in forum C Programming
    Replies: 10
    Last Post: 02-05-2003, 03:01 PM
  4. How do I write more efficient code?
    By minesweeper in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 11:08 AM
  5. Any better & efficient alternative to this C prg.
    By perlguy in forum C Programming
    Replies: 12
    Last Post: 05-24-2002, 03:00 AM