I am a computer programmer and my project is to take an arbitrary length ordered list of integers and generate another integer which is a reversible encoding of the list.
I did find a solution, but I wonder if there is a better solution in terms of efficiency. If mathematicians offer other solutions, I can evaluate them for efficiency. I'll represent my current solution as code, for clarity.
Imagine that we want to treat a group of numbers like a hierarchical namespace. Analogous to subomain.domain.tld or 127.99.0.1 or /directory/.../subdirectory/filename
In each of the examples above, we use a separator character. But we want our output to be numbers, composed entirely of digits.
Our trick: convert the numbers to octal and use "9" as the separator.
>>> lst = [127, 99, 0, 1]
>>> octnums = [oct(x) for x in lst] # encode in octal
>>> octnums
['0o177', '0o143', '0o0', '0o1']
>>> as_str = "9".join(octnum[2:] for octnum in octnums)
>>> int(as_str)
17791439091
This is a unique and reversible representation of that list of numbers as an integer.
Note that the number "8" and the string "99" will never appear in these numbers, so they are a subset of the normal integers.
Octal is selected because the language has a built-in function for it.
Is there a better way: one that uses either integer-space or CPU time more efficiently?