Jump to content

Index finite lists of positive integers: Difference between revisions

→‎{{header|Python}}: correct when list begins with 0s
(→‎{{header|Python}}: correct when list begins with 0s)
Line 294:
 
=={{header|Python}}==
<lang python>def rank(x): return int('a'.join(map(str, [1] + x)), 11)
 
def unrank(n):
s = ''
while n: s,n = "0123456789a"[n%11] + s, n//11
return map(int, s.split('a'))[1:]
 
l = [1, 2, 3, 10, 100, 987654321]
Line 309:
{{out}}
<pre>
[0, 1, 2, 3, 10, 100, 987654321]
207672721333439869642567444
14307647611639042485573
[0, 1, 2, 3, 10, 100, 987654321]
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.