Index finite lists of positive integers: Difference between revisions
Content deleted Content added
→{{header|Perl 6}}: not using Test on second thought |
|||
Line 270:
sub rank(@n) { compress (compress(@n), @n - 1)}
sub unrank(Int $n) { my ($a, $b) = expand $n, 2; expand $a, $b + 1 }
my @list = (^10).roll((2..20).pick);
my $rank = rank @list;
for ^10 {
my @unrank = unrank $_;
}</lang>
{{out}}
<pre>[7 1 4 7 7 0 2 7 7 0 7 7] -> 20570633300796394530947471 -> [7 1 4 7 7 0 2 7 7 0 7 7]
0 -> [0] -> 0
=={{header|Python}}==
|