How can a hash function return different values for the same input?

49 views Asked by At
def hashValue(a: List[int]) -> int:
    h = len(a)
    for val in a:
        h = h * 314159 + val
    return h 

length = len(grid[0])
for i in range(length):
    h = hashValue(grid[i])
    print(h)

for j in range(0,length):
    col = np.empty(length, dtype=int)
    for i in range(length):
        col[i] = grid[i][j]
    h = hashValue(col)
    print(h)

For this grid:

[[3, 1, 2, 2], [1, 4, 4, 5], [2, 4, 2, 2], [2, 4, 2, 2]]

Hashes for grid rows:

38963597787757876482482
38963535775657743299288
38963566781855853392646
38963566781855853392646

Hashes for grid cols:

4074304083303469490
4012291983170286295
4043298181280379654
4043298279976256935

But [3, 1, 2, 2] col index 0 is same as row index 0, so I would expect the same hash.

And [2, 4, 2, 2] col index 2 is same as row index 2, 3, so I would expect the same hash.

0

There are 0 answers