It is well known, in the field of Mathematics studying infinity, that the Cartesian product of any finite amount of countable sets is also countable.
Your task is to write two programs to implement this, one to map from list to integer, one to map from integer to list.
Your function must be bijective and deterministic, meaning that 1
will always map to a certain list, and 2
will always map to another certain list, etc...
Earlier, we mapped integers to a list consisting only of 0
and 1
.
However, now the list will consist of non-negative numbers.
Specs
- Program/function, reasonable input/output format.
- Whether the mapped integers start from
1
or starts from0
is your choice, meaning that0
doesn't have to (but may) map to anything. - The empty array
[]
must be encoded. - Input/output may be in any base.
- Sharing code between the two functions is allowed.
Scoring
This is code-golf. Lowest score wins.
Score is the sum of lengths (in bytes) of the two programs/functions.