Index finite lists of positive integers: Difference between revisions

Line 66:
406578125236287223374090483
4 5 7 9 0 8 8 7 4 8 8 4 1</pre>
 
=={{header|Python}}==
<lang python>def rank(x): return int('a'.join(map(str, x)), 11)
 
def unrank(n):
out = ()
while n: out,n = out + ("0123456789a"[n % 11],), n//11
return map(int, ''.join(reversed(out)).split('a'))
 
l = [1, 2, 3, 10, 100, 987654321]
print l
n = rank(l)
print n
l = unrank(n)
print l</lang>
{{out}}
<pre>
[1, 2, 3, 10, 100, 987654321]
14307647611639042485573
[1, 2, 3, 10, 100, 987654321]
</pre>
Anonymous user