Hello. I have tried numerous string permutation methods, and they work, but not for what I need. I need to permute a string such that I don't get any reversals:

abcd
abdc
acbd
acdb
adbc
adcb *
bacd
badc
bcad
bcda *

see how these are reversals of each other? this is the first few lines of output when I try to permute "abcd". Unfortunately I can't think of an algorithm to skip over any reversals. Thanks

Recommended Answers

All 3 Replies

How are you saving the generated Strings? Could you also save its reversed contents in a list to test against?

How are you saving the generated Strings? Could you also save its reversed contents in a list to test against?

well, I send each to another method that generates a number based off the string and adds it to the total. the thing is, I get duplicate numbers (because things like abcde and edcba result in the same number). Plus, I need to be able to go up to 19 or 20 factorial, and it would really help if the number of cases I need to check was cut in half.

Sorry, too little to go on for ideas.

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.