Results 1 to 5 of 5
  1. #1
    HexMurder's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    System.Diagnostics
    Posts
    344
    Reputation
    96
    Thanks
    3,170

    All Permutations of a word [C++]

    So i just started learning C++ and I've been looking up different beginners programs, most of which I've been able to complete without any issues. This one however has me STUCK. I can't even begin to think up what to code to solve this.

    Basically the challenge is to have a user input a word, and then have the console take the word, and output it with every possible permutation of that word, each on a new line.

    Here is a sample for the input cat

    cat
    cta
    act
    atc
    tac
    tca

    I'm sure this isn't as hard as it seems to me, but i'd really appreciate it if someone could solve this for me so i could take a look at the code!

  2. #2
    ESchrödinger's Avatar
    Join Date
    Oct 2014
    Gender
    male
    Location
    Austria
    Posts
    2
    Reputation
    10
    Thanks
    0
    Programming isn't about being able to write code, anyone can type on a keyboard as long as they have half a brain. Programming is all about problem solving and you seem to have come across a problem, and instead of facing it and trying all possible methods (which I highly doubt you did), all you did was ask for some code. Since I won't stand around and tell you about how you made a mistake, I'll give you a hint in solving this issue because giving you the code doesn't help anyone :

    Read these :

    Wikipedia - Permutations
    Wikipedia - Combinations

    then create a function that uses a formula instead of arrays and such and calculates the value. Counting chars would work too.

    Hope this helps, in a way.

  3. #3
    R3DDOT's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Location
    C://Windows/system32
    Posts
    347
    Reputation
    38
    Thanks
    2,366
    My Mood
    Cheerful
    Calculating the amount of permutations is easy:


    For a word with k-chars, and with each char repeating itself n1,n2,n3...nk times,respectively, then the total amount of permutations is:

    __________k!
    _____________________
    (n1!×n2!×n3! ×(…)× nk!)


    To show the permutations themselfs.. well, goood luck with that.
    I have no clue on how to do this efficiently.
    Last edited by R3DDOT; 11-01-2014 at 04:40 PM.

  4. #4
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    I did this 4 years ago using vectors relatively easily.

  5. #5
    R3DDOT's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Location
    C://Windows/system32
    Posts
    347
    Reputation
    38
    Thanks
    2,366
    My Mood
    Cheerful
    Quote Originally Posted by Auxilium View Post
    I did this 4 years ago using vectors relatively easily.
    It is easy to do words that don't have repeating characters, for the others it's lot harder.
    A unefficient way is logging all permutations and removing identical ones.

Similar Threads

  1. all the words like wtf and there explanation
    By Pepijntje in forum General
    Replies: 24
    Last Post: 12-07-2021, 05:57 PM
  2. ALL Can you help me for Chinese words?
    By hochantola in forum Mission Against Terror Help
    Replies: 4
    Last Post: 07-04-2013, 10:26 PM
  3. LOL ALL THREADS BELOW CONTAIN THE WORD FUCK
    By CyberGenius in forum Flaming & Rage
    Replies: 13
    Last Post: 03-11-2013, 08:51 PM
  4. [Release] Bypass all cencored word
    By sovanness in forum Mission Against Terror Hacks & Cheats
    Replies: 46
    Last Post: 11-30-2011, 05:54 PM
  5. Word out to all mpgh staff
    By psnbullet in forum Combat Arms Discussions
    Replies: 0
    Last Post: 12-23-2009, 02:16 PM

Tags for this Thread