Index finite lists of positive integers: Difference between revisions
Content added Content deleted
(→{{header|Python}}: correct when list begins with 0s) |
|||
Line 294: | Line 294: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<lang python>def rank(x): return int('a'.join(map(str, x)), 11) |
<lang python>def rank(x): return int('a'.join(map(str, [1] + x)), 11) |
||
def unrank(n): |
def unrank(n): |
||
s = '' |
s = '' |
||
while n: s,n = "0123456789a"[n%11] + s, n//11 |
while n: s,n = "0123456789a"[n%11] + s, n//11 |
||
return map(int, s.split('a')) |
return map(int, s.split('a'))[1:] |
||
l = [1, 2, 3, 10, 100, 987654321] |
l = [1, 2, 3, 10, 100, 987654321] |
||
Line 309: | Line 309: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
[1, 2, 3, 10, 100, 987654321] |
[0, 1, 2, 3, 10, 100, 987654321] |
||
207672721333439869642567444 |
|||
14307647611639042485573 |
|||
[1, 2, 3, 10, 100, 987654321] |
[0, 1, 2, 3, 10, 100, 987654321] |
||
</pre> |
</pre> |
||