every combination of letters

R

roger

Hi Folks,

I need to write two programs for a school assignment. One is an
"efficient" anagram program that will find all anagrams for a given
word by sorting all given letters of the supplied word and dictionary
which will then find all of the matching words.

The next version of the program (the "inefficient" example) is
supposed to try every combination of letters and find anagrams by pure
brute force by trying every combination of letters up to
len($suppliedWord) in length.

I'm not looking for someone to do this for me, I'm looking for advice
on how do I go about trying every possible combination of letters. It
sounds pretty easy on the surface but as I think about it more it
seems to get messier and messier.

Does soemone know of a "clean" method I can use to iterate through
every possible combination of letters?


Thanks,
Roger
 
C

chance

roger said:
Hi Folks,
I need to write two programs for a school assignment. One is an
"efficient" anagram program that will find all anagrams for a given
word by sorting all given letters of the supplied word and dictionary
which will then find all of the matching words.
The next version of the program (the "inefficient" example) is
supposed to try every combination of letters and find anagrams by pure
brute force by trying every combination of letters up to
len($suppliedWord) in length.
I'm not looking for someone to do this for me, I'm looking for advice
on how do I go about trying every possible combination of letters. It
sounds pretty easy on the surface but as I think about it more it
seems to get messier and messier.
Does soemone know of a "clean" method I can use to iterate through
every possible combination of letters?


My shoot-from the hip advice:

1) write the inefficient code first. Then observe why its
inefficient and fix it.

2) for the permutation generation do it recursively. Thats just more fun:

a) if I'm being asked to give every permutation of a single
letter, just return that letter.

b) otw loop through the whole word a letter at a time,
concatenating the 'current letter' with all the permutations
of all the other letters.
 
T

Tom

I'm not looking for someone to do this for me, I'm looking for advice
as with the majority of job assignments you will 'possibly' take on 'on the
job'.
That is why Engineers make such good $$ :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top