Okay I really suck at titles! If someone has a better one, please feel free to edit!
Anyway, what I'd like to do is find an equation that maps all pairs $(x,y)$ of integers $0$ to $27$ (inclusive) to an integer $z$ in the same range.
Additional constraints:
- If $x = y$, then $z = x = y$
- Otherwise, avoid $z = x$ and $z = y$ if possible
- Results of $z$ should be reasonably evenly distributed, but some variation is okay
- For every value of $z$ there must exist at least one pair $(x,y)$ where $x \ne y$
So my initial attempt at solving this was simple enough:
$$z = \sqrt{(x+1) \times (y+1)}-1 \tag{rounded to nearest integer}$$
It's fairly simple to see that the first constraint is met. It doesn't meet the second one but that's not too big of an issue. Results for $z$ were biased towards the middle of the range, but again that's okay. The major flaw is that the only possible solution for $z = 27$ is $(x,y) = (27,27)$, which is not acceptable.
Any help solving this would be greatly appreciated!
mod 28instead, and I also realised that I forgot I also needed $f(x,y) = f(y,x)$, but I fixed that by just switching $x$ and $y$ to be the same way around. Thank you very much for your help! – Niet the Dark Absol Jan 02 '14 at 16:08if(x>y) list(x,y) = [y,x];, followed by the formula you gave. – Niet the Dark Absol Jan 02 '14 at 16:16