Reputation: 21
I have a two dimensional array of letters. Any letter can vary according to a certain alphabet. I want to make a unique key for this array according to the letters and its position. For example, if the array is 3 * 3 and the alphabet is {0, a, b, c, *}, the array can be in the form like:
0 b c
b * a
a a 0
I have tried Key = sum(code(letter)*(r*3+c))
for all r and c, where r and c are the row and the column, but it still gives me the same key for different array forms.
What do I miss?
P.S. code(letter)
is a mapping function to convert the letter into a value.
Upvotes: 2
Views: 185
Reputation: 13461
You need to take into account the size of alphabet. If code and indices are all zero based it would be:
key = Sum(code(letter)*pow(L, r*C+c))
where L is the number of letters and C is the number of columns. However watch out for numeric overflow. For larger alphabets or matrices you need to use one of the following:
Upvotes: 3