Identify letter combinations where order is not important?

D

D r . P r o z a c

Hi,

I want to identify combinations of letters (a-z)... to make the combination
unique, but where the order of these letters is not important.

For example:
'er' and 're' should have the same unique identity.
 
S

Simon Biber

D r . P r o z a c said:
Hi,

I want to identify combinations of letters (a-z)... to make the combination
unique, but where the order of these letters is not important.

For example:
'er' and 're' should have the same unique identity.

This is not a question about the C programming language. Either rephrase it
or find somewhere more appropriate. If you can come up with a more complete
description of what you want your program to do you could post to
comp.programming
 
R

Robert Stankowic

D r . P r o z a c said:
Hi,

I want to identify combinations of letters (a-z)... to make the combination
unique, but where the order of these letters is not important.

For example:
'er' and 're' should have the same unique identity.

If I don't misunderstand what you want to do...

You could use an array of structs like in
struct
{
char letters[SOME_SIZE_LARGE_ENOUGH_TO_HOLD_THE_LONGEST_SEQUENCE];
unsigned long id;
}[ENOUGH_TO_HOLD_ALL_PATTERNS] = {0};

Now iterate through the structs, fill the letters member of the structs with
your character sequences and qsort the letter arrays in _descending_ order
(so the zeroes from the initialisation will remain at the end of the char
arrays), then qsort the structs themselves, using the "letters" members as
sort criteria.
Finally you iterate through the array of structs again, assign values to the
"id" members (starting with 0 and only incrementing if struct[n].letters
compares unequal to the struct[n-1].letters, and you are done.

HTH
Robert
 
M

Micah Cowan

D r . P r o z a c said:
Hi,

I want to identify combinations of letters (a-z)... to make the combination
unique, but where the order of these letters is not important.

For example:
'er' and 're' should have the same unique identity.

Simply choose a consistent ordering and order the letters
appropriately every time you encounter them: use the ordered
version as the identity.

-Micah
 

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,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top