# Bus number

Is there an integer that is the unique representation of *n* other integers, where n is greater than or equal to 1? I guess the answer is no. If the criterion is narrowed to a number rather than an integer, would it become possible? Don’t ask why—even I’ve forgotten why, genuinely—but I’m trying to represent sequential bus journeys in a single number. In this scenario, it could be obtained by merely stringing together three-digit strings, left-padding with zeros where necessary, given that London bus numbers are always three digits or less. And these would even be comma-separated, such is our penchant for separating numbers into three-digit chunks. But what if they weren’t?

### Comments

**2 Responses to “Bus number”**

**Leave a Reply**

Actually, yes, there is always an integer that is the unique representation of any n other integers, where n is greater than or equal to 1…

First we need a function called nth_prime which simply describes the sequence 2,3,5,7,11…

Now map each number x in your list to the xth prime ie 1->2, 2->3, 3->5 … 8->19 …

Finally multiply the results, and by the principal of every number having a unique list of prime factors, you have a unique number.

Example:

Encode 2,5,10 -> 3,11,29 -> 3*11*29=957

There now exists a further capability to decide whether a given encoded list of numbers contains any given number. Can you see how?

Example:

Does the list of numbers encoded as 957 contain the number 7?

957 / nth_prime(7) = 56.29411765

56.29411765 is not a whole number so 7 is not in the encoded list.

Note: If you need 0 and negative numbers too, then just map the sequence 0,1,-1,2,-2,3,-3… to the list of primes.

Now a question for the reader:

Can you see how this could be used in excel to decide for example if a given list of numbers contains duplicates.

Not quite what I was after, Tom. You need to be able to interpret from the numbers the order in which they occurred. So 57 then 72 is different from 72 then 57.

Maybe convert each of the numbers to base nine then nine-separate each from the next, given that the nine would never be used.

So 57 and 72 are 63 and 80 respectively. So their unique number would be 63,980.