Letter Combination
-
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"
-
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"
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
-
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"
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.