# Identify letter combinations where order is not important?

Discussion in 'C Programming' started by D r . P r o z a c, Oct 19, 2003.

1. ### D r . P r o z a cGuest

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.

--
Peter.

D r . P r o z a c, Oct 19, 2003

2. ### Simon BiberGuest

" D r . P r o z a c" <> wrote:
> 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

--
Simon.

Simon Biber, Oct 19, 2003

3. ### Robert StankowicGuest

" D r . P r o z a c" <> schrieb im Newsbeitrag
news:bmu3me\$mi6\$...
> 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

Robert Stankowic, Oct 20, 2003
4. ### Micah CowanGuest

" D r . P r o z a c" <> writes:

> 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

Micah Cowan, Oct 20, 2003