Given a set of $n$ items (i.e., $\{X_1, X_2, X_3 ... X_n\}$), for all $\binom{n}{2}$ combinations, is there a function I can use to calculate unique labels in the range of $[1, \frac{n (n-1)}{2}]$, given indexes $i, j \in [1, n]$ and $i \neq j$?
E.g., If $n = 5$, I might have the following diagonal table of combinations:
5 1
4 D 2
3 C G 3
2 B F I 4
A E H J
- $A$ would be a real number between 1 and 10 that can be calculated by either $f(1, 2)$ or $f(2, 1)$.
- $D$ would be a real number between 1 and 10 that can be calculated by either $f(1, 5)$ or $f(5, 1)$
- $H$ would be a real number between 1 and 10 that can be calculated by either $f(3, 4)$ or $f(4, 3)$
...and each letter's value would not be repeated for another letter. E.g., if $D = 4$ then none of the other letters can be $4$.
If it helps to have some context, I'm writing some computer code and want to index into an array to store the results of the somewhat computationally-expensive combination procedure. The pairs will be received in random order and some may be repeated (in which case I want to lookup the previously computed value).