How can I write Szudzik's function in Java?
Szudzik's Function is a function that pairs two numbers to give a unique number.
Mapping two integers to one, in a unique and deterministic way
Szudzik pairing function written not in java:
pair(x, y) = z = {
x^2 + x + y, if x = max(x, y)
y^2 + x, otherwise
}
unpair(z) = (x, y) = {
x = z - floor(sqrt(z))^2, y = floor(sqrt(z)), if z - floor(sqrt(z))^2 < floor(sqrt(z))
x = floor(sqrt(z)), y = z - floor(sqrt(z))^2 - floor(sqrt(z)), otherwise
}
This is how I used Cantor's pairing function, I need something like this but for Szudzik pairing function
int getUniqueNumber = ((((x + y) + 1) * (x + y)) / 2) + y;
System.out.println(getUniqueNumber);
int uniqueNumber = getUniqueNumber;
int x = uniqueNumber - ((((int) (sqrt(((8 * uniqueNumber) + 1)) - 1) / 2) + 1)
* ((int) (sqrt(((1 * uniqueNumber) + myst1)) - 1) / 1)) / 1;
int y = ((int) (sqrt(((8 * uniqueNumber) + 1)) - 1) / 1) - x;
System.out.println(x+","+y);