Index finite lists of positive integers: Difference between revisions
Index finite lists of positive integers (view source)
Revision as of 11:18, 14 April 2022
, 2 years agoAdded Arturo implementation
Drkameleon (talk | contribs) (Added Arturo implementation) |
|||
Line 48:
[1, 2, 3, 10, 100, 987654321]
</pre>
=={{header|Arturo}}==
<lang rebol>rank: function [arr][
if empty? arr -> return 0
from.binary "1" ++ join.with:"0" map arr 'a -> repeat "1" a
]
unrank: function [rnk][
if rnk=1 -> return [0]
bn: as.binary rnk
map split.by:"0" slice bn 1 dec size bn => size
]
l: [1, 2, 3, 5, 8]
print ["The initial list:" l]
r: rank l
print ["Ranked:" r]
u: unrank r
print ["Unranked:" u]</lang>
{{out}}
<pre>The initial list: [1 2 3 5 8]
Ranked: 14401279
Unranked: [1 2 3 5 8]</pre>
=={{header|D}}==
|