Skip to main content
8 of 8
edited tags
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661

Map a list of indefinite size to a number!

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 from 0 is your choice, meaning that 0 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 . Lowest score wins.

Score is the sum of lengths (in bytes) of the two programs/functions.

Leaky Nun
  • 50.1k
  • 6
  • 110
  • 284