# Generate unique number, from 2 different numbers [closed]

I have 2 different numbers, from example 7 and 8. I need generate third "unique" number using given numbers, that is, if from 7 and 8 we obtain some X number, this X number not will be obtain from some other 2 numbers, X must be generate only from 7 and 8. can make this? Thanks

-

## closed as not a real question by martini, William, Noah Snyder, draks ..., J. M.Oct 5 '12 at 13:00

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

$(a,b)\mapsto 2^a 3^b$. – mjqxxxx Sep 25 '12 at 13:29
and "a" must be less than "b"? or order no sense and this algorithm will works always? – OTARIKI Sep 25 '12 at 13:55
Google pairing function. This is surely a duplicate question. – Bill Dubuque Sep 25 '12 at 15:51

If the order matters and your two numbers are X and Y you could try things like:

$2^X3^Y$ or $(10^X-1)10^Y$ or $2^X(2Y-1)$

But the original question doesn't state whether X and Y can be zero or negative etc, and the kind of function you choose depends on what you want to use it for.

-
X and Y, are always positive numbers (not zero also), as I see, more simplest way in this case is, first variant in your answer, thanks very much, thansk everyone. – OTARIKI Sep 25 '12 at 13:45

If $a,b$ are nonnegative integers, then you can let $$x = \frac{a-b-1+(a+b+1)^2}2.$$ This $x$ will always be a non-negative integer and different inputs produce different values of $x$. In fact, this method is not wasteful: All nonnegative numbers $x$ can be obtained by a suitable (and unique) choice of $a$ and $b$.

-

So what you want is an injective function $\mathbb N\times\mathbb N\to\mathbb N$.

There are many possible choices for that -- one of the simplest (among those that don't waste space by leaving many possible results unused) is $$(a,b)\mapsto \frac{(a+b)(a+b+1)}2 + a$$ which is known as Cantor's zig-zag.

-

Are the numbers positive integers, or can they be arbitrary real numbers? Does the order of the numbers matter, or can the numbers $7$ and $8$ generate the same number $X$ as the numbers $8$ and $7$?

I will assume that the numbers are positive integers, and that the order of them does not matter. Then you can put all your pairs of numbers in a long sequence, and count along the sequence to get your number $X$. For instance, you can use the sequence $$(1,1)\qquad (1,2)\qquad (2,2) \qquad (1,3) \qquad (2,3) \qquad (3,3) \qquad (1,4)\ \ \ \ \ \ \ \ \ \ \ \$$ $$(2,4)\qquad (3,4)\qquad (4,4) \qquad (1,5) \qquad (2,5) \qquad (3,5) \qquad (4,5) \quad {\rm etc.}$$ Following this pattern, your pair of numbers $7$ and $8$ will then be the $35$th element of this sequence, so $X=35$.

(It is in principle possible to do this for real numbers too, since ${\Bbb R}^2$ and $\Bbb R$ have the same cardinality, but you will not get an explicit expression for $X$ in that case.)

-
I think at least part of the question was how to enumerate the pairs in the first place. – Henning Makholm Sep 25 '12 at 13:30
I thought the pattern would be clear - it's the alphabetical ordering of words of length 2. – Per Manne Sep 25 '12 at 13:34