Find a function that maps x,y to $[0, n ( n + 1) / 2)$

63 Views Asked by At

Can you find me a bijective function that maps positive integers $x, y$ such that $0 \leq x < y \leq n$ to integers in $[0, n(n+1)/2)$ to use as a hash function?

1

There are 1 best solutions below

3
On BEST ANSWER

I'm sure there are many. One is $$\frac{1}{2} (n-x+1) (n-x)-n-1+y.$$