Scramble the word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Scholar
    New Member
    • Aug 2008
    • 9

    Scramble the word

    Hello friends,
    there is yet another problem for you...
    We have got a string say HOUR
    Now we need a program that can choose the specified number of words say n from this word in all possible ways and displays them ...for example in this case
    for n=3 the output should be
    HOU
    OUR
    URH
    RHO
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    In your example, are you looking for all of the 3-letter combinations or are you also required to weed out combinations that are not found in the dictionary?

    Have you had any courses in probability and/or statistics?

    Comment

    • boxfish
      Recognized Expert Contributor
      • Mar 2008
      • 469

      #3
      It looks from the example like the program is supposed to make words that use the letters in order, but words that go off the end of the original word wrap around to the beginning. No need for any probability. Here's another example of a word:
      word = 12345
      n = 4
      combinations are:
      1234
      2345
      3451
      4512
      5123
      This should be fairly easy using the modulus operator to wrap the indices around.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        The reason I asked about any background in probability and/or statistics is that there's a mathematical concept introduced in those courses that is at the core of what this problem is all about.
        Yes; I'm being deliberately coy.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          Ummm I'm not so sure.
          'hour' should have 4! = 24 different combinations where as
          'hou' or 'our' should have 3! = 6 different combinations
          The next_permutatio n () C++ generic algorithm demonstrates this.
          Code:
          int main()
          {
              char* s="ABCD";
              for(int i=0;i<24;i++)
              { next_permutation(s,s+4);
              cout<<(i%8?'\t':'\n')<<s;
              }
          system("pause");
          return 0;
          //prints
          ABDC ACBD ACDB ADBC ADCB BACD BADC BCAD
          BCDA BDAC BDCA CABD CADB CBAD CBDA CDAB
          CDBA DABC DACB DBAC DBCA DCAB DCBA ABCD

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Scholar
            Hello friends,
            there is yet another problem for you...
            We have got a string say HOUR
            Now we need a program that can choose the specified number of words say n from this word in all possible ways and displays them ...for example in this case
            for n=3 the output should be
            HOU
            OUR
            URH
            RHO
            You have to specify the definition of that sequence; why not HOU, HOR, HUR
            and OUR? You either want P(4,3) or C(4,3) or something else; please elaborate.

            kind regards,

            Jos

            Comment

            • curiously enough
              New Member
              • Aug 2008
              • 79

              #7
              From your example, I think what you want is C(a,n), meaning no repetitions.
              You are not only asking for the code, which they won't give you, but you also want them to guess what the output of the program should be. Try to be more specific next time.

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                To understand what P(4,3) and C(4,3) mean you should Google "permutatio n combination".

                Comment

                • Scholar
                  New Member
                  • Aug 2008
                  • 9

                  #9
                  Originally posted by JosAH
                  You have to specify the definition of that sequence; why not HOU, HOR, HUR
                  and OUR? You either want P(4,3) or C(4,3) or something else; please elaborate.

                  kind regards,

                  Jos
                  Actually i am concerned with only selection of the letters not their sequence .So i need C(4,3) nt P(4,3).

                  Comment

                  Working...