Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Letter Combination

Letter Combination

Scheduled Pinned Locked Moved C#
algorithmstutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silvyster
    wrote on last edited by
    #1

    I want to ask if someone has already have an article or working algorithm where it can get all the combination possible in a given word. Example: "ABCD" possible combinations or arrangement without duplicates: "ABCD" "ABC" "ABD" "BCD" "AB" "AC" "AD" "BC" "CA" <--- is the same as "AC" "CBA" <--- is the same as "ABC" or "BCA" "BD"

    S G 2 Replies Last reply
    0
    • S Silvyster

      I want to ask if someone has already have an article or working algorithm where it can get all the combination possible in a given word. Example: "ABCD" possible combinations or arrangement without duplicates: "ABCD" "ABC" "ABD" "BCD" "AB" "AC" "AD" "BC" "CA" <--- is the same as "AC" "CBA" <--- is the same as "ABC" or "BCA" "BD"

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      You could do it recursively. All combinations of "ABCD" can be calculated as "A", and all combinations of "BCD", and all combinations of "BCD" with an "A" added at the beginning. All combinations of "BCD" is: "B" and all combinations of "CD" and all combinations of "CD" with a B added at the beginning All combinations of "CD" is: "C" and all combinations of "D" and all combinations of "D" with a C added at the beginning. All combinations of "D" is: "D" Pass back up. All combinations of "CD" is: "C" and "D" and "CD". Pass back up. All combinations of "BCD" is: "B" and "C" and "D" and "CD" and "BC" and "BD" and "BCD". Pass back up. all Combinations of "ABCD" is: "A" and "B" and "C" and "D" and "CD" and "BC" and "BD" and "BCD" and "AB" and "AC" and "AD" and "ACD" and "ABC" and "ABD" and "ABCD". And there is your answer: "A" "B" "C" "D" "AB" "AC" "AD" "BC" "BD" "CD" "ABC" "ABD" "ACD" "BCD" "ABCD" Of course recursion probably isn't the best way. It would be easier with a for loop, but everyone knows recursion is more fun. ;)

      Simon

      1 Reply Last reply
      0
      • S Silvyster

        I want to ask if someone has already have an article or working algorithm where it can get all the combination possible in a given word. Example: "ABCD" possible combinations or arrangement without duplicates: "ABCD" "ABC" "ABD" "BCD" "AB" "AC" "AD" "BC" "CA" <--- is the same as "AC" "CBA" <--- is the same as "ABC" or "BCA" "BD"

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        That is easy by using recursion. Combine each letter with all combinations of the letters after it: All combinations in "ABCD" is: Combine "A" with each of all combinations in "BCD". Combine "A" with each of the letters in "BCD". Combine "B" with each of all combinations in "CD". Combine "B" with each of the letters in "CD". Combine "C" with each of the letters in "D".

        Despite everything, the person most likely to be fooling you next is yourself.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups