Sort the letters of string in alphabetical order: Difference between revisions
Content added Content deleted
(insert →Pascal: , allegedly add new external links [spam detection false positive]) |
(→{{header|Lua}}: added Lua solution) |
||
Line 657: | Line 657: | ||
Sorted -> .aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy |
Sorted -> .aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy |
||
</pre> |
</pre> |
||
=={{header|Lua}}== |
|||
Not idiomatic, ASCII assumed.. |
|||
<lang lua>function sorted(s) |
|||
local b, c = {}, "" |
|||
s:gsub("(.)", function(c) local a=string.byte(c) b[a]=(b[a] or 0)+1 end) |
|||
for i = 0, 255 do if b[i] then c=c..string.rep(string.char(i),b[i]) end end |
|||
return c |
|||
end |
|||
print(sorted("Now is the time for all good men to come to the aid of their country."))</lang> |
|||
{{out}} |
|||
<pre> .Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |