posted 14 years ago
A number can be encoded as an integer array as follows. The first element of the array is any number and if it is negative then the encoded number is negative. Each digit of the number is the absolute value of the difference of two adjacent elements of the array. The most significant digit of the number is the absolute value of the difference of the first two elements of the array. For example, the array {2, -3, -2, 6, 9, 18} encodes the number 51839 because
· 5 is abs(2 - (-3))
· 1 is abs(-3 - (-2))
· 8 is abs(-2 - 6)
· 3 is abs(6-9)
· 9 is abs(9-18)
The number is positive because the first element of the array is >= 0.