Registered: Oct 2003
Here is a function that people might find useful when performing enumerations. It enumerates all strings with k colors, of any length.
It does not have any gaps, and here is its inverse function:
unenum[ls_,k_]:=(k^Length[ls] - 1)/(k-1)+FromDigits[ls,k]
It relies on the formula for geometric sums, and the efficiency of the IntegerDigits function.
For comparison, some other enumeration functions compute
the strings of k colors of fixed length with IntegerDigits[n,k,len]
finite strings of arbitrary length and arbitrary colors with the Leibniz-Godel function (p.1120)
strings of fixed length with arbitrary colors with the pairing function
(p.1127 and the recent forum thread).
Report this post to a moderator | IP: Logged