I have an array of size 4,9,16 or 25 (according to the input), and the numbers in the array are the same, but less by one (if the size of the array is 9, then the largest element in the array will be 8) the numbers start at 0 and I wanted would do some kind of algorithm to create some checksum for the array so that I can compare that the 2 arrays are equal without looping the whole array and checking each element one by one.
Where can I get this information? I need something as simple as possible. Thanks.
edit: just to understand what I want:
-All the numbers in the array are different, so [0,1,1,2] is not valid, because there is a repeating element (1)
- the position of the numbers matters, therefore [0,1,2,3] does not coincide with [3,2,1,0]
- the array will contain the number 0, so this should also be taken into account.
EDIT:
Ok, I tried to implement the Fletcher algorithm: http://en.wikipedia.org/wiki/Fletcher%27s_checksum#Straightforward
int fletcher(int array[], int size){ int i; int sum1=0; int sum2=0; for(i=0;i<size;i++){ sum1=(sum1+array[i])%255; sum2=(sum2+sum1)%255; } return (sum2 << 8) | sum1; }
Honestly, I have no idea what the return line does, but unfortunately the algorithm does not work. For arrays [2,1,3,0] and [1,3,2,0] I get the same checksum.
EDIT2:
here is another Adler checksum http://en.wikipedia.org/wiki/Adler-32#Example_implementation
This also does not work. Arrays [2,0,3,1] and [1,3,0,2] generate the same checksum. I'm losing hope here, any ideas?