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"

Recommended Answers

All 6 Replies

If you sorted them into alphabetical order you'd be able to tell if they were the same or not.

eg

ABA gets sorted to AAB

To find all the combinations of say words of 3 letters from a word of 4 cannot be that difficult. To exclude the "identicals" I would sum their ASCII-char values of a word and test if they are the same.

That might not necessarily work.

AED would = BCF

33+37+36 = 106
34+35+37 = 106

Only true way is to sort them and compare them.

You are quite right LizR! The minute I sent it I knew I was wrong.
But btw. your example to prove it looks a little weird(ASCII code for A=65,B=66 etc.)

I thought lowercase was 65.. all the same, whatever :)

Lowercase a is 97, but indeed whatever...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.