Mathematically, this can be done for finite sequences, but not very practical, because the required numbers grow very quickly: 67 7 (about 2 42 ) of different lengths-7 sequences of integers from 1 ... 67, not to mention longer sequences and large integers.
For a simple example of such a function, compare the sequence [1,6,7,8,9,45,67] with the value 2 1 * 3 6 * 5 7 * 7 8 * 11 9 * 13 45 * 17 67 . The bases are primes, forces are elements in a sequence.
Inverse matching is calculated by dividing - the number of times you can divide your value by 2 is the first element in the sequence, etc. The biggest simple value factor tells you how long the sequence will be.
If you want to allow 0 in the sequence, as well as positive numbers, add 1 to all elements when you raise primes to powers. Or use power 2 to indicate the length of the sequence, then start coding the elements starting at 3 .
Godel used such encodings in the proof of his incompleteness theorems.
As Kendall Frey says, it is impossible to define a function that maps every infinite sequence of integers to another integer. This is a consequence of Cantor’s proof that many degrees of natural numbers are uncountable: you cannot even inject all infinite sequences of elements from {true, false} into integers, not to mention all infinite sequences of elements from integers.
For more practical approaches, think of encoding a sequence of integers as a sequence of bytes, rather than as a number. The final sequence of bytes can easily be considered a binary value, therefore, this is a number, you just do not use it as such. The general idea of the sequence of your example is the sequence of bytes: [1,6,7,8,9,45,67] used, for example, in JSON. This is a 136-bit number. The mathematical function for the inverse mapping includes arithmetic modulo a degree of 256, subtracting the number 48, multiplying by 10, etc. :-)